Date: Sun, 3 Aug 2014 01:51:48 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r269453 - stable/10/lib/libc/gen Message-ID: <201408030151.s731pmvO012267@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: marcel Date: Sun Aug 3 01:51:48 2014 New Revision: 269453 URL: http://svnweb.freebsd.org/changeset/base/269453 Log: 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. Modified: stable/10/lib/libc/gen/getlogin.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/gen/getlogin.c ============================================================================== --- stable/10/lib/libc/gen/getlogin.c Sun Aug 3 00:35:10 2014 (r269452) +++ stable/10/lib/libc/gen/getlogin.c Sun Aug 3 01:51:48 2014 (r269453) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408030151.s731pmvO012267>