]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Handle too-small buffers in Linux getlogin_r.
authorUlrich Drepper <drepper@redhat.com>
Wed, 5 May 2010 16:44:50 +0000 (09:44 -0700)
committerUlrich Drepper <drepper@redhat.com>
Wed, 5 May 2010 16:44:50 +0000 (09:44 -0700)
ChangeLog
NEWS
sysdeps/unix/sysv/linux/getlogin_r.c

index a7fdafa4130db021d4f0e8b9e85bb8ba62c204ad..0d3d04a59f3fa7be63060a292448982a811e8ae4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2010-05-05  Ulrich Drepper  <drepper@redhat.com>
 
+       [BZ #11571]
+       * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
+       too small buffers according to the standard.
+
        * sysdeps/unix/sysv/linux/kernel-features.h: Alpha doesn't have to be
        handled here anymore.
        Patch mostly by Matt Turner <mattst88@gmail.com>.
diff --git a/NEWS b/NEWS
index f508959c5e2c7989e8b61b64accb9c1d109598a3..c0c74be6f701c2543394619d40caaba0a4b5210c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,7 @@ Version 2.12
   11185, 11186, 11187, 11188, 11189, 11190, 11191, 11192, 11193, 11194,
   11200, 11230, 11235, 11242, 11254, 11258, 11271, 11272, 11276, 11279,
   11287, 11292, 11319, 11332, 11333, 11387, 11389, 11390, 11394, 11397,
-  11410, 11438, 11449, 11470, 11471, 11520, 11537, 11538
+  11410, 11438, 11449, 11470, 11471, 11520, 11537, 11538, 11571
 
 * New interfaces: pthread_getname_np, pthread_setname_np
 
index d9c66fe2598fb9dbc0fe1a6577f5db4205980392..dad2671e802bf64f006e53c3deb0aab26b0242ce 100644 (file)
@@ -81,13 +81,22 @@ __getlogin_r_loginuid (name, namesize)
   if (tpwd == NULL)
     goto fail;
 
-  strncpy (name, pwd.pw_name, namesize - 1);
-  name[namesize - 1] = '\0';
-
+  int result = 0;
+  size_t needed = strlen (pwd.pw_name) + 1;
+  if (needed > namesize)
+    {
+      __set_errno (ERANGE);
+      result = ERANGE;
+      goto out;
+    }
+
+  memcpy (name, pwd.pw_name, needed);
+
+ out:
   if (use_malloc)
     free (buf);
 
-  return 0;
+  return result;
 }