]> granicus.if.org Git - sudo/commitdiff
sudo_setenv() now exits on memory alloc failure instead of returning -1.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 14 Sep 2000 20:48:58 +0000 (20:48 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 14 Sep 2000 20:48:58 +0000 (20:48 +0000)
sudo.c
sudo.h
sudo_setenv.c

diff --git a/sudo.c b/sudo.c
index 70204d276be68262b2414eb9063dffd1c7aa207a..163b679b9e0becbdd947858894babd2c0954f128 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -374,11 +374,7 @@ main(argc, argv)
 
        /* Replace the PATH envariable with a secure one. */
        if (def_str(I_SECURE_PATH) && !user_is_exempt())
-           if (sudo_setenv("PATH", def_str(I_SECURE_PATH))) {
-               (void) fprintf(stderr, "%s: cannot allocate memory!\n",
-                   Argv[0]);
-               exit(1);
-           }
+           sudo_setenv("PATH", def_str(I_SECURE_PATH));
 
        /* Restore coredumpsize resource limit. */
 #if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL)
@@ -390,7 +386,7 @@ main(argc, argv)
 
        /* Set $HOME for `sudo -H'.  Only valid at PERM_RUNAS. */
        if ((sudo_mode & MODE_RESET_HOME) && runas_homedir)
-           (void) sudo_setenv("HOME", runas_homedir);
+           sudo_setenv("HOME", runas_homedir);
 
 #ifndef PROFILING
        if ((sudo_mode & MODE_BACKGROUND) && fork() > 0)
@@ -739,10 +735,7 @@ add_env(contiguous)
     } else {
        buf = user_cmnd;
     }
-    if (sudo_setenv("SUDO_COMMAND", buf)) {
-       (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
-       exit(1);
-    }
+    sudo_setenv("SUDO_COMMAND", buf);
     if (NewArgc > 1)
        free(buf);
 
@@ -754,32 +747,16 @@ add_env(contiguous)
            user_args = NULL;
     }
 
-    /* Add the SUDO_USER environment variable. */
-    if (sudo_setenv("SUDO_USER", user_name)) {
-       (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
-       exit(1);
-    }
-
-    /* Add the SUDO_UID environment variable. */
+    /* Add the SUDO_USER, SUDO_UID, SUDO_GID environment variables. */
+    sudo_setenv("SUDO_USER", user_name);
     (void) sprintf(idstr, "%ld", (long) user_uid);
-    if (sudo_setenv("SUDO_UID", idstr)) {
-       (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
-       exit(1);
-    }
-
-    /* Add the SUDO_GID environment variable. */
+    sudo_setenv("SUDO_UID", idstr);
     (void) sprintf(idstr, "%ld", (long) user_gid);
-    if (sudo_setenv("SUDO_GID", idstr)) {
-       (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
-       exit(1);
-    }
+    sudo_setenv("SUDO_GID", idstr);
 
     /* Set PS1 if SUDO_PS1 is set. */
     if ((buf = getenv("SUDO_PS1")))
-       if (sudo_setenv("PS1", buf)) {
-           (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
-           exit(1);
-       }
+       sudo_setenv("PS1", buf);
 }
 
 /*
@@ -949,18 +926,8 @@ set_perms(perm, sudo_mode)
 
                                    /* Set $USER and $LOGNAME to target user */
                                    if (def_flag(I_LOGNAME)) {
-                                       if (sudo_setenv("USER", pw->pw_name)) {
-                                           (void) fprintf(stderr,
-                                               "%s: cannot allocate memory!\n",
-                                               Argv[0]);
-                                           exit(1);
-                                       }
-                                       if (sudo_setenv("LOGNAME", pw->pw_name)) {
-                                           (void) fprintf(stderr,
-                                               "%s: cannot allocate memory!\n",
-                                               Argv[0]);
-                                           exit(1);
-                                       }
+                                       sudo_setenv("USER", pw->pw_name);
+                                       sudo_setenv("LOGNAME", pw->pw_name);
                                    }
 
                                    if (def_flag(I_LOGINCLASS)) {
diff --git a/sudo.h b/sudo.h
index b80b9bc86ce51d8ad0b81fd673e152ec41f90b81..d8b34146b873e23b7cb1c01c0bbe2a50a0689862 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -192,7 +192,7 @@ int vasprintf               __P((char **, const char *, va_list));
 int strcasecmp         __P((const char *, const char *));
 #endif
 char *sudo_goodpath    __P((const char *));
-int sudo_setenv                __P((char *, char *));
+void sudo_setenv       __P((char *, char *));
 char *tgetpass         __P((const char *, int, int));
 int find_path          __P((char *, char **));
 void check_user                __P((void));
index 55344413bf2cb145bb5d84fccb7951a8ccf2c578..8162fc1289661983f5b68a4d2eaf45bfd56e7e4a 100644 (file)
@@ -64,23 +64,28 @@ static const char rcsid[] = "$Sudo$";
 
 
 /*
- * Add a string of the form "var=val" to the environment.  If we are unable
- * to expand the current environent, return -1, else return 0.
+ * Add a string of the form "var=val" to the environment.  Exits if it is
+ * unable to expand the current environent.
  */
-int
+void
 sudo_setenv(var, val)
     char *var;
     char *val;
 {
 
 #ifdef HAVE_SETENV
-    return(setenv(var, val, 1));
+    if (setenv(var, val, 1) == -1) {
+       (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
+       exit(1);
+    }
 #else
     char *envstring, *tmp;
 
     envstring = tmp = (char *) malloc(strlen(var) + strlen(val) + 2);
-    if (envstring == NULL)
-       return(-1);
+    if (envstring == NULL) {
+       (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
+       exit(1);
+    }
 
     while ((*tmp++ = *var++))
        ;
@@ -90,6 +95,6 @@ sudo_setenv(var, val)
     while ((*tmp++ = *val++))
        ;
 
-    return(putenv(envstring));
+    putenv(envstring);
 #endif /* HAVE_SETENV */
 }