]> granicus.if.org Git - sudo/commitdiff
Add back allocation of the env struct in rebuild_env but save
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 29 Jul 2007 22:32:47 +0000 (22:32 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 29 Jul 2007 22:32:47 +0000 (22:32 +0000)
a copy of the old pointer and free it before returning.

env.c

diff --git a/env.c b/env.c
index 7ef93c8018dd3c47ecebf178bf1acfb512388da9..0d5468f4db972631583c8d945d4a344070e29788 100644 (file)
--- a/env.c
+++ b/env.c
@@ -456,7 +456,7 @@ rebuild_env(sudo_mode, noexec)
     int sudo_mode;
     int noexec;
 {
-    char **ep, *cp, *ps1;
+    char **old_envp, **ep, *cp, *ps1;
     char idbuf[MAX_UID_T_LEN];
     unsigned int didvar;
 
@@ -465,6 +465,10 @@ rebuild_env(sudo_mode, noexec)
      */
     ps1 = NULL;
     didvar = 0;
+    env.env_len = 0;
+    env.env_size = 128;
+    old_envp = env.envp;
+    env.envp = emalloc2(env.env_size, sizeof(char *));
     if (def_env_reset) {
        /* Pull in vars we want to keep from the old environment. */
        for (ep = environ; *ep; ep++) {
@@ -657,6 +661,7 @@ rebuild_env(sudo_mode, noexec)
 
     /* Install new environment. */
     environ = env.envp;
+    efree(old_envp);
 }
 
 void