svn commit: r264161 - head/lib/libc/gen
Marcel Moolenaar
marcel at FreeBSD.org
Sat Apr 5 18:14:59 UTC 2014
Author: marcel
Date: Sat Apr 5 18:14:58 2014
New Revision: 264161
URL: http://svnweb.freebsd.org/changeset/base/264161
Log:
The getlogin_basic() function can return a 0 status with a NULL
pointer for the login name (result). Make sure to handle that
case properly. Improve robustness by checking namelen and then
nul-terminating the provided buffer to simplify subsequent logic.
Obtained from: Juniper Networks, Inc.
MFC after: 1 week
Modified:
head/lib/libc/gen/getlogin.c
Modified: head/lib/libc/gen/getlogin.c
==============================================================================
--- head/lib/libc/gen/getlogin.c Sat Apr 5 18:13:28 2014 (r264160)
+++ head/lib/libc/gen/getlogin.c Sat Apr 5 18:14:58 2014 (r264161)
@@ -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);
More information about the svn-src-all
mailing list