about summary refs log tree commit diff
path: root/sysdeps/unix/sysv
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r--sysdeps/unix/sysv/linux/getlogin_r.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sysdeps/unix/sysv/linux/getlogin_r.c b/sysdeps/unix/sysv/linux/getlogin_r.c
index d9c66fe259..dad2671e80 100644
--- a/sysdeps/unix/sysv/linux/getlogin_r.c
+++ b/sysdeps/unix/sysv/linux/getlogin_r.c
@@ -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;
 }