]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: more robust sysconf() usage [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 31 Jan 2012 13:23:26 +0000 (14:23 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 31 Jan 2012 13:23:26 +0000 (14:23 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.c

index e80b137ba3f3978b44a8f8c74dd31f6266e88b63..3a904f2f88af7fb347a015589a51157d032bf9aa 100644 (file)
@@ -644,18 +644,19 @@ static struct passwd *get_passwd_entry(const char *username,
                                         struct passwd *pwd)
 {
        struct passwd *res = NULL;
-       size_t sz;
+       size_t sz = 16384;
        int x;
 
        if (!pwdbuf || !username)
                return NULL;
 
 #ifdef _SC_GETPW_R_SIZE_MAX
-       sz = sysconf(_SC_GETPW_R_SIZE_MAX);
-       if (sz <= 0)
+       {
+               long xsz = sysconf(_SC_GETPW_R_SIZE_MAX);
+               if (xsz > 0)
+                       sz = (size_t) xsz;
+       }
 #endif
-               sz = 16384;
-
        *pwdbuf = xrealloc(*pwdbuf, sz);
 
        x = getpwnam_r(username, pwd, *pwdbuf, sz, &res);