Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars

*** 18,36 **** * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ - #pragma ident "%Z%%M% %I% %E% SMI" - #pragma weak _getlogin = getlogin #pragma weak _getlogin_r = getlogin_r #include "lint.h" #include <sys/types.h> --- 18,36 ---- * * CDDL HEADER END */ /* + * Copyright (c) 2013 Gary Mills + * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ #pragma weak _getlogin = getlogin #pragma weak _getlogin_r = getlogin_r #include "lint.h" #include <sys/types.h>
*** 46,58 **** #include <synch.h> #include <mtlib.h> #include "tsd.h" /* ! * XXX - _POSIX_LOGIN_NAME_MAX limits the length of a login name. The utmpx ! * interface provides for a 32 character login name, but for the sake of ! * compatibility, we are still using the old utmp-imposed limit. */ /* * POSIX.1c Draft-6 version of the function getlogin_r. * It was implemented by Solaris 2.3. --- 46,57 ---- #include <synch.h> #include <mtlib.h> #include "tsd.h" /* ! * Use the full length of a login name, from LOGIN_NAME_MAX . ! * The utmpx interface provides for a 32 character login name. */ /* * POSIX.1c Draft-6 version of the function getlogin_r. * It was implemented by Solaris 2.3.
*** 62,71 **** --- 61,71 ---- { int uf; off64_t me; struct futmpx ubuf; + /* Required minimum */ if (namelen < _POSIX_LOGIN_NAME_MAX) { errno = ERANGE; return (NULL); }
*** 79,91 **** return (NULL); } (void) close(uf); if (ubuf.ut_user[0] == '\0') return (NULL); (void) strncpy(&answer[0], &ubuf.ut_user[0], ! _POSIX_LOGIN_NAME_MAX - 1); ! answer[_POSIX_LOGIN_NAME_MAX - 1] = '\0'; return (&answer[0]); } /* * POSIX.1c standard version of the function getlogin_r. --- 79,97 ---- return (NULL); } (void) close(uf); if (ubuf.ut_user[0] == '\0') return (NULL); + + /* Insufficient buffer size */ + if (namelen < strnlen(&ubuf.ut_user[0], LOGIN_NAME_MAX - 1)) { + errno = ERANGE; + return (NULL); + } (void) strncpy(&answer[0], &ubuf.ut_user[0], ! LOGIN_NAME_MAX - 1); ! answer[LOGIN_NAME_MAX - 1] = '\0'; return (&answer[0]); } /* * POSIX.1c standard version of the function getlogin_r.
*** 109,119 **** } char * getlogin(void) { ! char *answer = tsdalloc(_T_LOGIN, _POSIX_LOGIN_NAME_MAX, NULL); if (answer == NULL) return (NULL); ! return (getlogin_r(answer, _POSIX_LOGIN_NAME_MAX)); } --- 115,125 ---- } char * getlogin(void) { ! char *answer = tsdalloc(_T_LOGIN, LOGIN_NAME_MAX, NULL); if (answer == NULL) return (NULL); ! return (getlogin_r(answer, LOGIN_NAME_MAX)); }