From: millert Date: Sat, 12 Apr 1997 07:18:56 +0000 (+0000) Subject: Fixed coredump when passwd file is missing or unavailable. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c5d8187993c9957950b60e593f545435a26a73fc;p=openbsd Fixed coredump when passwd file is missing or unavailable. Reported by Jason Downs and Klee Dienes (via a Debian Linux bug report). --- diff --git a/gnu/usr.bin/sudo/sudo/sudo.c b/gnu/usr.bin/sudo/sudo/sudo.c index c735f8c116c..c1615a47469 100644 --- a/gnu/usr.bin/sudo/sudo/sudo.c +++ b/gnu/usr.bin/sudo/sudo/sudo.c @@ -51,7 +51,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sudo.c,v 1.2 1996/11/17 16:34:04 millert Exp $"; +static char rcsid[] = "$Id: sudo.c,v 1.3 1997/04/12 07:18:56 millert Exp $"; #endif /* lint */ #define MAIN @@ -405,10 +405,7 @@ static void load_globals(sudo_mode) * if necesary. It is assumed that euid is 0 at this point so we * can read the shadow passwd file if necesary. */ - user_pw_ent = sudo_getpwuid(getuid()); - set_perms(PERM_ROOT, sudo_mode); - set_perms(PERM_USER, sudo_mode); - if (user_pw_ent == NULL) { + if ((user_pw_ent = sudo_getpwuid(getuid())) == NULL) { /* need to make a fake user_pw_ent */ struct passwd pw_ent; char pw_name[MAX_UID_T_LEN+1]; @@ -425,6 +422,10 @@ static void load_globals(sudo_mode) exit(1); } + /* Set euid == user and ruid == root */ + set_perms(PERM_ROOT, sudo_mode); + set_perms(PERM_USER, sudo_mode); + #ifdef HAVE_TZSET (void) tzset(); /* set the timezone if applicable */ #endif /* HAVE_TZSET */ diff --git a/gnu/usr.bin/sudo/visudo/visudo.c b/gnu/usr.bin/sudo/visudo/visudo.c index 45d446172e2..f977b314977 100644 --- a/gnu/usr.bin/sudo/visudo/visudo.c +++ b/gnu/usr.bin/sudo/visudo/visudo.c @@ -26,7 +26,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: visudo.c,v 1.3 1996/11/17 16:34:08 millert Exp $"; +static char rcsid[] = "$Id: visudo.c,v 1.4 1997/04/12 07:18:57 millert Exp $"; #endif /* lint */ #include "config.h" @@ -156,7 +156,12 @@ int main(argc, argv) usage(); /* user_pw_ent needs to point to something... */ - user_pw_ent = getpwuid(getuid()); + if ((user_pw_ent = getpwuid(getuid())) == NULL) { + (void) fprintf(stderr, "%s: Can't find you in the passwd database: ", + Argv[0]); + perror(stmp); + exit(1); + } #ifdef ENV_EDITOR /*