aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2010-06-19 09:54:28 -0700
committerUlrich Drepper <drepper@redhat.com>2010-06-19 09:54:28 -0700
commit63c4ed22b5048c8701d8806026c23cc95f0df756 (patch)
tree65f3c6559d0329a649d4c2474e3216d4bb89d22d
parent765ade4b29d9fcc4b236b4f3ae5bfd1174978442 (diff)
downloadglibc-63c4ed22b5048c8701d8806026c23cc95f0df756.zip
glibc-63c4ed22b5048c8701d8806026c23cc95f0df756.tar.gz
glibc-63c4ed22b5048c8701d8806026c23cc95f0df756.tar.bz2
Fix error handling in Linux getlogin*.
-rw-r--r--ChangeLog9
-rw-r--r--sysdeps/unix/sysv/linux/getlogin.c5
-rw-r--r--sysdeps/unix/sysv/linux/getlogin_r.c24
3 files changed, 25 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 863a762..f50f11d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-06-19 Ulrich Drepper <drepper@redhat.com>
+
+ * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
+ OOM in getpwuid_r correctly. Return error number when the caller
+ should return, otherwise -1.
+ (getlogin_r): Adjust to return also for result of __getlogin_r_loginuid
+ call returning > 0 value.
+ * sysdeps/unix/sysv/linux/getlogin.c (getlogin): Likewise.
+
2010-06-07 Andreas Schwab <schwab@redhat.com>
* dlfcn/Makefile: Remove explicit dependencies on libc.so and
diff --git a/sysdeps/unix/sysv/linux/getlogin.c b/sysdeps/unix/sysv/linux/getlogin.c
index 4d15db0..58e37c4 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 dad2671..5c3de69 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);
}