Skip to content

Commit 0e93138

Browse files
committed
Check for MAXLOGNAME and UT_NAMESIZE in configure and use them (in that order)
if available, falling back to a hard-coded maximum login name length of 255 if neither is available.
1 parent 434c1a0 commit 0e93138

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

Modules/posixmodule.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9539,15 +9539,21 @@ os_getlogin_impl(PyObject *module)
95399539
else
95409540
result = PyErr_SetFromWindowsErr(GetLastError());
95419541
#elif defined (HAVE_GETLOGIN_R)
9542-
/* AFAIK the maximum length should be 32, but this is not checkable */
9543-
char name[64];
9542+
# if defined (HAVE_MAXLOGNAME)
9543+
char name[MAXLOGNAME + 1];
9544+
# elif defined (HAVE_UT_NAMESIZE)
9545+
char name[UT_NAMESIZE + 1];
9546+
# else
9547+
char name[256];
9548+
# endif
95449549
int err = getlogin_r(name, sizeof(name));
95459550
if (err) {
95469551
int old_errno = errno;
95479552
errno = -err;
95489553
posix_error();
95499554
errno = old_errno;
9550-
} else {
9555+
}
9556+
else {
95519557
result = PyUnicode_DecodeFSDefault(name);
95529558
}
95539559
#else

configure

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5427,6 +5427,18 @@ PY_CHECK_FUNC([setgroups], [
54275427
#endif
54285428
])
54295429

5430+
AC_CHECK_DECL([MAXLOGNAME],
5431+
[AC_DEFINE([HAVE_MAXLOGNAME], [1],
5432+
[Define if you have the 'MAXLOGNAME' constant.])],
5433+
[],
5434+
[@%:@include <sys/params.h>])
5435+
5436+
AC_CHECK_DECLS([UT_NAMESIZE],
5437+
[AC_DEFINE([HAVE_UT_NAMESIZE], [1],
5438+
[Define if you have the 'HAVE_UT_NAMESIZE' constant.])],
5439+
[],
5440+
[@%:@include <utmp.h>])
5441+
54305442
# check for openpty, login_tty, and forkpty
54315443

54325444
AC_CHECK_FUNCS([openpty], [],

pyconfig.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,12 @@
16331633
/* Define to 1 if the system has the type '__uint128_t'. */
16341634
#undef HAVE___UINT128_T
16351635

1636+
/* Define to 1 if you have the MAXLOGNAME constant. */
1637+
#undef HAVE_MAXLOGNAME
1638+
1639+
/* Define to 1 if you have the UT_NAMESIZE constant. */
1640+
#undef HAVE_UT_NAMESIZE
1641+
16361642
/* Define to 1 if 'major', 'minor', and 'makedev' are declared in <mkdev.h>.
16371643
*/
16381644
#undef MAJOR_IN_MKDEV

0 commit comments

Comments
 (0)