fix from Peter Samuelson for use-after-free bug parsing wildcards in sudoers
[debian/sudo] / sudo.c
diff --git a/sudo.c b/sudo.c
index 372727a33ceb13927c7e98371ba7effbd394aa9c..6eb5930b165cd1c03c6ced4d304ba724fdb2917d 100644 (file)
--- a/sudo.c
+++ b/sudo.c
 #include "version.h"
 
 #ifndef lint
-__unused __unused static const char rcsid[] = "$Sudo: sudo.c,v 1.369.2.38 2008/03/05 19:34:49 millert Exp $";
+__unused __unused static const char rcsid[] = "$Sudo: sudo.c,v 1.369.2.41 2008/06/21 19:04:07 millert Exp $";
 #endif /* lint */
 
 /*
@@ -131,6 +131,7 @@ extern char **insert_env_vars               __P((char **, struct list_member *));
 extern struct passwd *sudo_getpwnam    __P((const char *));
 extern struct passwd *sudo_getpwuid    __P((uid_t));
 extern struct passwd *sudo_pwdup       __P((const struct passwd *));
+extern void runas_resetgroups          __P((void));
 
 /*
  * Globals
@@ -155,7 +156,7 @@ login_cap_t *lc;
 #ifdef HAVE_BSD_AUTH_H
 char *login_style;
 #endif /* HAVE_BSD_AUTH_H */
-sigaction_t saved_sa_int, saved_sa_quit, saved_sa_tstp, saved_sa_chld;
+sigaction_t saved_sa_int, saved_sa_quit, saved_sa_tstp;
 
 
 int
@@ -204,8 +205,6 @@ main(argc, argv, envp)
     (void) sigaction(SIGINT, &sa, &saved_sa_int);
     (void) sigaction(SIGQUIT, &sa, &saved_sa_quit);
     (void) sigaction(SIGTSTP, &sa, &saved_sa_tstp);
-    sa.sa_handler = reapchild;
-    (void) sigaction(SIGCHLD, &sa, &saved_sa_chld);
 
     /*
      * Turn off core dumps and close open files.
@@ -280,7 +279,7 @@ main(argc, argv, envp)
 
        /* Local sudoers file overrides LDAP if we have a match. */
        v = sudoers_lookup(pwflag);
-       if (ISSET(v, VALIDATE_OK))
+       if (validated == VALIDATE_ERROR || ISSET(v, VALIDATE_OK))
            validated = v;
     }
 #else
@@ -437,7 +436,6 @@ main(argc, argv, envp)
        (void) sigaction(SIGINT, &saved_sa_int, NULL);
        (void) sigaction(SIGQUIT, &saved_sa_quit, NULL);
        (void) sigaction(SIGTSTP, &saved_sa_tstp, NULL);
-       (void) sigaction(SIGCHLD, &saved_sa_chld, NULL);
 
 #ifndef PROFILING
        if (ISSET(sudo_mode, MODE_BACKGROUND) && fork() > 0)
@@ -532,10 +530,9 @@ init_vars(sudo_mode, envp)
        user_host = user_shost = "localhost";
     else {
        user_host = estrdup(thost);
-       if ((p = strchr(user_host, '.'))) {
-           *p = '\0';
-           user_shost = estrdup(user_host);
-           *p = '.';
+       if (def_fqdn) {
+           /* Defer call to set_fqdn() until log_error() is safe. */
+           user_shost = user_host;
        } else {
            user_shost = user_host;
        }
@@ -611,9 +608,6 @@ init_vars(sudo_mode, envp)
     if (nohostname)
        log_error(USE_ERRNO|MSG_ONLY, "can't get hostname");
 
-    /* We don't query FQDN yet, it might get disabled later. Querying is done
-     * when host matching is executed and def_fqdn still true */
-
     set_runaspw(*user_runas);          /* may call log_error() */
     if (*user_runas[0] == '#' && runas_pw->pw_name && runas_pw->pw_name[0])
        *user_runas = estrdup(runas_pw->pw_name);
@@ -920,7 +914,10 @@ args_done:
            warnx("you may not specify environment variables in edit mode");
        usage(1);
     }
-
+    if (ISSET(rval, MODE_PRESERVE_ENV) && ISSET(rval, MODE_LOGIN_SHELL)) {
+       warnx("you may not specify both the `-i' and `-E' options");
+       usage(1);
+    }
     if (user_runas != NULL && !ISSET(rval, (MODE_EDIT|MODE_RUN))) {
        if (excl != '\0')
            warnx("the `-u' and '-%c' options may not be used together", excl);
@@ -1244,6 +1241,7 @@ set_runaspw(user)
        if (runas_pw == NULL)
            log_error(NO_MAIL|MSG_ONLY, "no passwd entry for %s!", user);
     }
+    runas_resetgroups();
     return(TRUE);
 }