summaryrefslogtreecommitdiffstats
path: root/login-utils/login.c
diff options
context:
space:
mode:
authorKarel Zak2015-12-15 12:25:56 +0100
committerKarel Zak2015-12-15 12:33:34 +0100
commitf7ac9e71b18fa7314151f2ab65ee0bdd2ea89c07 (patch)
treed089c7b2317441444ab356d17fb200286aa0a550 /login-utils/login.c
parentMerge branch 'test-fixes' of https://github.com/rudimeier/util-linux (diff)
downloadkernel-qcow2-util-linux-f7ac9e71b18fa7314151f2ab65ee0bdd2ea89c07.tar.gz
kernel-qcow2-util-linux-f7ac9e71b18fa7314151f2ab65ee0bdd2ea89c07.tar.xz
kernel-qcow2-util-linux-f7ac9e71b18fa7314151f2ab65ee0bdd2ea89c07.zip
login, mount: fix __SC_GETPW_R_SIZE_MAX usage
sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd buffer (see getpwnam_r man page or POSIX). This is not large enough in some cases. Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN). Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'login-utils/login.c')
-rw-r--r--login-utils/login.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/login-utils/login.c b/login-utils/login.c
index b70846771..2551631d3 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -674,22 +674,14 @@ static struct passwd *get_passwd_entry(const char *username,
struct passwd *pwd)
{
struct passwd *res = NULL;
- size_t sz = 16384;
int x;
if (!pwdbuf || !username)
return NULL;
-#ifdef _SC_GETPW_R_SIZE_MAX
- {
- long xsz = sysconf(_SC_GETPW_R_SIZE_MAX);
- if (xsz > 0)
- sz = (size_t) xsz;
- }
-#endif
- *pwdbuf = xrealloc(*pwdbuf, sz);
+ *pwdbuf = xrealloc(*pwdbuf, UL_GETPW_BUFSIZ);
- x = getpwnam_r(username, pwd, *pwdbuf, sz, &res);
+ x = getpwnam_r(username, pwd, *pwdbuf, UL_GETPW_BUFSIZ, &res);
if (!res) {
errno = x;
return NULL;