about summary refs log tree commit diff
path: root/sysdeps/mach
diff options
context:
space:
mode:
authorPino Toscano <toscano.pino@tiscali.it>2012-07-21 00:16:11 +0200
committerPino Toscano <toscano.pino@tiscali.it>2012-07-21 00:16:11 +0200
commitb3404dbdebb977f0f8d6099fa466ebbe6eb9157e (patch)
tree9e096da64416bc11528878ac2f7f9254db671487 /sysdeps/mach
parent0ced335ac081474e12c89709c81cf2f2094c5351 (diff)
downloadglibc-b3404dbdebb977f0f8d6099fa466ebbe6eb9157e.tar.gz
glibc-b3404dbdebb977f0f8d6099fa466ebbe6eb9157e.tar.xz
glibc-b3404dbdebb977f0f8d6099fa466ebbe6eb9157e.zip
Hurd: compliance fixes for getlogin_r
- make LOGIN non-static, as it would make getlogin_r no more reentrant; change its type to string_t
- fail with ERANGE if NAME has not enough space for the actual login string
- copy with memcpy only the chars of the string
Diffstat (limited to 'sysdeps/mach')
-rw-r--r--sysdeps/mach/hurd/getlogin_r.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sysdeps/mach/hurd/getlogin_r.c b/sysdeps/mach/hurd/getlogin_r.c
index 2539e6b0a0..5410709e71 100644
--- a/sysdeps/mach/hurd/getlogin_r.c
+++ b/sysdeps/mach/hurd/getlogin_r.c
@@ -29,13 +29,20 @@ getlogin_r (name, name_len)
      char *name;
      size_t name_len;
 {
-  static char login[1024];	/* XXX */
+  string_t login;
   error_t err;
 
   if (err = __USEPORT (PROC, __proc_getlogin (port, login)))
     return errno = err;
 
-  strncpy (name, login, name_len);
+  size_t len = __strnlen (login, sizeof login - 1) + 1;
+  if (len > name_len)
+    {
+      errno = ERANGE;
+      return errno;
+    }
+
+  memcpy (name, login, len);
   return 0;
 }
 libc_hidden_def (getlogin_r)