Blame SOURCES/glibc-getlogin-r.patch

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