diff options
author | marcel <marcel@FreeBSD.org> | 2014-08-03 01:51:48 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2014-08-03 01:51:48 +0000 |
commit | b37299ed785ac4eb45217050ecf4a151341f2b1b (patch) | |
tree | a67db3f6b4b72c684b1159ac7ab17618b874fe7b /lib/libc | |
parent | 672efbb4a9b586b3eef3f75a536d3e8dfcd223c4 (diff) | |
download | FreeBSD-src-b37299ed785ac4eb45217050ecf4a151341f2b1b.zip FreeBSD-src-b37299ed785ac4eb45217050ecf4a151341f2b1b.tar.gz |
MFC 264161: Handle the fact that the getlogin_basic() function can return
a 0 status with a NULL pointer for the login name (result).
Obtained from: Juniper Networks, Inc.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/getlogin.c | 11 |
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); |