Blame SOURCES/glibc-getlogin-r.patch

b9ba6d
2010-05-05  Ulrich Drepper  <drepper@redhat.com>
b9ba6d
b9ba6d
	[BZ #11571]
b9ba6d
	* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
b9ba6d
	too small buffers according to the standard.
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
@@ -81,13 +81,22 @@ __getlogin_r_loginuid (name, namesize)
b9ba6d
   if (tpwd == NULL)
b9ba6d
     goto fail;
b9ba6d
 
b9ba6d
-  strncpy (name, pwd.pw_name, namesize - 1);
b9ba6d
-  name[namesize - 1] = '\0';
b9ba6d
+  int result = 0;
b9ba6d
+  size_t needed = strlen (pwd.pw_name) + 1;
b9ba6d
+  if (needed > namesize)
b9ba6d
+    {
b9ba6d
+      __set_errno (ERANGE);
b9ba6d
+      result = ERANGE;
b9ba6d
+      goto out;
b9ba6d
+    }
b9ba6d
 
b9ba6d
+  memcpy (name, pwd.pw_name, needed);
b9ba6d
+
b9ba6d
+ out:
b9ba6d
   if (use_malloc)
b9ba6d
     free (buf);
b9ba6d
 
b9ba6d
-  return 0;
b9ba6d
+  return result;
b9ba6d
 }
b9ba6d
 
b9ba6d