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
This commit is contained in:
parent
9fe6f910fd
commit
eef9f6d258
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user