summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/getlogin.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c
index 4dab3cb..7ab4cba 100644
--- a/lib/libc/gen/getlogin.c
+++ b/lib/libc/gen/getlogin.c
@@ -87,11 +87,16 @@ getlogin_r(char *logname, int namelen)
char *result;
int len;
int status;
-
+
+ if (namelen < 1)
+ return (ERANGE);
+ logname[0] = '\0';
+
THREAD_LOCK();
result = getlogin_basic(&status);
- if (status == 0) {
- if ((len = strlen(result) + 1) > namelen)
+ if (status == 0 && result != NULL) {
+ len = strlen(result) + 1;
+ if (len > namelen)
status = ERANGE;
else
strncpy(logname, result, len);
OpenPOWER on IntegriCloud