diff options
author | Ulrich Drepper <drepper@redhat.com> | 2010-06-19 09:54:28 -0700 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2010-06-19 09:54:28 -0700 |
commit | 63c4ed22b5048c8701d8806026c23cc95f0df756 (patch) | |
tree | 65f3c6559d0329a649d4c2474e3216d4bb89d22d /sysdeps | |
parent | 765ade4b29d9fcc4b236b4f3ae5bfd1174978442 (diff) | |
download | glibc-63c4ed22b5048c8701d8806026c23cc95f0df756.tar glibc-63c4ed22b5048c8701d8806026c23cc95f0df756.tar.gz glibc-63c4ed22b5048c8701d8806026c23cc95f0df756.tar.bz2 glibc-63c4ed22b5048c8701d8806026c23cc95f0df756.zip |
Fix error handling in Linux getlogin*.
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/unix/sysv/linux/getlogin.c | 5 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/getlogin_r.c | 24 |
2 files changed, 16 insertions, 13 deletions
diff --git a/sysdeps/unix/sysv/linux/getlogin.c b/sysdeps/unix/sysv/linux/getlogin.c index 4d15db093d..58e37c4ab4 100644 --- a/sysdeps/unix/sysv/linux/getlogin.c +++ b/sysdeps/unix/sysv/linux/getlogin.c @@ -32,8 +32,9 @@ char * getlogin (void) { - if (__getlogin_r_loginuid (name, sizeof (name)) == 0) - return name; + int res = __getlogin_r_loginuid (name, sizeof (name)); + if (res >= 0) + return res == 0 ? name : NULL; return getlogin_fd0 (); } diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c index dad2671e80..5c3de69e88 100644 --- a/sysdeps/unix/sysv/linux/getlogin_r.c +++ b/sysdeps/unix/sysv/linux/getlogin_r.c @@ -58,30 +58,31 @@ __getlogin_r_loginuid (name, namesize) bool use_malloc = false; struct passwd pwd; struct passwd *tpwd; + int result = 0; int res; - while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) != 0) + while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) == ERANGE) if (__libc_use_alloca (2 * buflen)) - extend_alloca (buf, buflen, 2 * buflen); + buf = extend_alloca (buf, buflen, 2 * buflen); else { buflen *= 2; char *newp = realloc (use_malloc ? buf : NULL, buflen); if (newp == NULL) { - fail: - if (use_malloc) - free (buf); - return 1; + result = ENOMEM; + goto out; } buf = newp; use_malloc = true; } - if (tpwd == NULL) - goto fail; + if (res != 0) + { + result = -1; + goto out; + } - int result = 0; size_t needed = strlen (pwd.pw_name) + 1; if (needed > namesize) { @@ -109,8 +110,9 @@ getlogin_r (name, namesize) char *name; size_t namesize; { - if (__getlogin_r_loginuid (name, namesize) == 0) - return 0; + int res = __getlogin_r_loginuid (name, namesize); + if (res >= 0) + return res; return getlogin_r_fd0 (name, namesize); } |