summaryrefslogtreecommitdiff
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.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/sysdeps/unix/getlogin_r.c b/sysdeps/unix/getlogin_r.c
index a78e554860..444df7e4d3 100644
--- a/sysdeps/unix/getlogin_r.c
+++ b/sysdeps/unix/getlogin_r.c
@@ -1,5 +1,5 @@
/* Reentrant function to return the current login name. Unix version.
- Copyright (C) 1991-2016 Free Software Foundation, Inc.
+ Copyright (C) 1991-2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -80,7 +80,7 @@ __getlogin_r (char *name, size_t name_len)
if (result == 0)
{
- size_t needed = strlen (ut->ut_user) + 1;
+ size_t needed = __strnlen (ut->ut_user, UT_NAMESIZE) + 1;
if (needed > name_len)
{
@@ -89,7 +89,8 @@ __getlogin_r (char *name, size_t name_len)
}
else
{
- memcpy (name, ut->ut_user, needed);
+ memcpy (name, ut->ut_user, needed - 1);
+ name[needed - 1] = 0;
result = 0;
}
}