vtysh: Fix, guard against NULL pointer dereference

getpwuid() may fail returning a null value leaving subsequent
code vulnerable to a null pointer dereference.

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
Tested-by: NetDEF CI System <cisystem@netdef.org>
This commit is contained in:
Jafar Al-Gharaibeh 2016-08-01 18:14:38 -05:00 committed by Donald Sharp
parent bfe15094c2
commit 6d128e1d78

View File

@ -195,7 +195,11 @@ vtysh_auth (void)
struct vtysh_user *user;
struct passwd *passwd;
passwd = getpwuid (geteuid ());
if ((passwd = getpwuid (geteuid ())) == NULL)
{
fprintf (stderr, "could not lookup user ID %d\n", (int) geteuid());
exit (1);
}
user = user_lookup (passwd->pw_name);
if (user && user->nopassword)