Blame SOURCES/glibc-rh621959.patch

b9ba6d
2010-08-06  Ulrich Drepper  <drepper@redhat.com>
b9ba6d
b9ba6d
	* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
b9ba6d
	Also fail if tpwd after pwuid call is NULL.
b9ba6d
b9ba6d
2010-06-21  Andreas Schwab <schwab@redhat.com>
b9ba6d
b9ba6d
	* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
b9ba6d
	Restore proper fallback handling.
b9ba6d
b9ba6d
2010-06-19  Ulrich Drepper  <drepper@redhat.com>
b9ba6d
b9ba6d
	* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
b9ba6d
	OOM in getpwuid_r correctly.  Return error number when the caller
b9ba6d
	should return, otherwise -1.
b9ba6d
	(getlogin_r): Adjust to return also for result of __getlogin_r_loginuid
b9ba6d
	call returning > 0 value.
b9ba6d
	* sysdeps/unix/sysv/linux/getlogin.c (getlogin): Likewise.
b9ba6d
b9ba6d
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
b9ba6d
@@ -32,8 +32,9 @@
b9ba6d
 char *
b9ba6d
 getlogin (void)
b9ba6d
 {
b9ba6d
-  if (__getlogin_r_loginuid (name, sizeof (name)) == 0)
b9ba6d
-    return name;
b9ba6d
+  int res = __getlogin_r_loginuid (name, sizeof (name));
b9ba6d
+  if (res >= 0)
b9ba6d
+    return res == 0 ? name : NULL;
b9ba6d
 
b9ba6d
   return getlogin_fd0 ();
b9ba6d
 }
b9ba6d
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin_r.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
b9ba6d
@@ -27,6 +27,10 @@ static int getlogin_r_fd0 (char *name, s
b9ba6d
 #undef getlogin_r
b9ba6d
 
b9ba6d
 
b9ba6d
+/* Try to determine login name from /proc/self/loginuid and return 0
b9ba6d
+   if successful.  If /proc/self/loginuid cannot be read return -1.
b9ba6d
+   Otherwise return the error number.  */
b9ba6d
+
b9ba6d
 int
b9ba6d
 attribute_hidden
b9ba6d
 __getlogin_r_loginuid (name, namesize)
b9ba6d
@@ -35,7 +39,7 @@ __getlogin_r_loginuid (name, namesize)
b9ba6d
 {
b9ba6d
   int fd = open_not_cancel_2 ("/proc/self/loginuid", O_RDONLY);
b9ba6d
   if (fd == -1)
b9ba6d
-    return 1;
b9ba6d
+    return -1;
b9ba6d
 
b9ba6d
   /* We are reading a 32-bit number.  12 bytes are enough for the text
b9ba6d
      representation.  If not, something is wrong.  */
b9ba6d
@@ -51,37 +55,38 @@ __getlogin_r_loginuid (name, namesize)
b9ba6d
       || (uidbuf[n] = '\0',
b9ba6d
 	  uid = strtoul (uidbuf, &endp, 10),
b9ba6d
 	  endp == uidbuf || *endp != '\0'))
b9ba6d
-    return 1;
b9ba6d
+    return -1;
b9ba6d
 
b9ba6d
   size_t buflen = 1024;
b9ba6d
   char *buf = alloca (buflen);
b9ba6d
   bool use_malloc = false;
b9ba6d
   struct passwd pwd;
b9ba6d
   struct passwd *tpwd;
b9ba6d
+  int result = 0;
b9ba6d
   int res;
b9ba6d
 
b9ba6d
-  while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) != 0)
b9ba6d
+  while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) == ERANGE)
b9ba6d
     if (__libc_use_alloca (2 * buflen))
b9ba6d
-      extend_alloca (buf, buflen, 2 * buflen);
b9ba6d
+      buf = extend_alloca (buf, buflen, 2 * buflen);
b9ba6d
     else
b9ba6d
       {
b9ba6d
 	buflen *= 2;
b9ba6d
 	char *newp = realloc (use_malloc ? buf : NULL, buflen);
b9ba6d
 	if (newp == NULL)
b9ba6d
 	  {
b9ba6d
-	  fail:
b9ba6d
-	    if (use_malloc)
b9ba6d
-	      free (buf);
b9ba6d
-	    return 1;
b9ba6d
+	    result = ENOMEM;
b9ba6d
+	    goto out;
b9ba6d
 	  }
b9ba6d
 	buf = newp;
b9ba6d
 	use_malloc = true;
b9ba6d
       }
b9ba6d
 
b9ba6d
-  if (tpwd == NULL)
b9ba6d
-    goto fail;
b9ba6d
+  if (res != 0 || tpwd == NULL)
b9ba6d
+    {
b9ba6d
+      result = -1;
b9ba6d
+      goto out;
b9ba6d
+    }
b9ba6d
 
b9ba6d
-  int result = 0;
b9ba6d
   size_t needed = strlen (pwd.pw_name) + 1;
b9ba6d
   if (needed > namesize)
b9ba6d
     {
b9ba6d
@@ -109,8 +114,9 @@ getlogin_r (name, namesize)
b9ba6d
      char *name;
b9ba6d
      size_t namesize;
b9ba6d
 {
b9ba6d
-  if (__getlogin_r_loginuid (name, namesize) == 0)
b9ba6d
-    return 0;
b9ba6d
+  int res = __getlogin_r_loginuid (name, namesize);
b9ba6d
+  if (res >= 0)
b9ba6d
+    return res;
b9ba6d
 
b9ba6d
   return getlogin_r_fd0 (name, namesize);
b9ba6d
 }