about summary refs log tree commit diff
path: root/sysdeps/unix/getlogin_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/getlogin_r.c')
-rw-r--r--sysdeps/unix/getlogin_r.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sysdeps/unix/getlogin_r.c b/sysdeps/unix/getlogin_r.c
index f80b2c7518..aa2c0617e6 100644
--- a/sysdeps/unix/getlogin_r.c
+++ b/sysdeps/unix/getlogin_r.c
@@ -72,8 +72,18 @@ getlogin_r (name, name_len)
     }
   else
     {
-      strncpy (name, ut->ut_line, name_len);
-      result = 0;
+      size_t needed = strlen (ut->ut_line) + 1;
+
+      if (needed < name_len)
+	{
+	  __set_errno (ERANGE);
+	  result = ERANGE;
+	}
+      else
+	{
+	  memcpy (name, ut->ut_line, needed);
+	  result = 0;
+	}
     }
   endutent_r (&utmp_data);