]> granicus.if.org Git - sudo/commitdiff
In unsetenv(), assign ep in the for loop instead of doing it earlier.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 25 Jun 2010 17:42:50 +0000 (13:42 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 25 Jun 2010 17:42:50 +0000 (13:42 -0400)
This version of the code does not change env.envp in between when
ep is assigned and when it is used but older versions (e.g. 1.7.2) do.

--HG--
branch : 1.7

env.c

diff --git a/env.c b/env.c
index 75466241e38e59deda1f939f14ccb856daf944f0..d9df824f52829a0925650b3f81301452a03be6aa 100644 (file)
--- a/env.c
+++ b/env.c
@@ -356,7 +356,7 @@ int
 unsetenv(var)
     const char *var;
 {
-    char **ep = env.envp;
+    char **ep;
     size_t len;
 
     if (env.envp == NULL)
@@ -377,7 +377,7 @@ unsetenv(var)
 #endif
 
     len = strlen(var);
-    while (*ep != NULL) {
+    for (ep = env.envp; *ep != NULL;) {
        if (strncmp(var, *ep, len) == 0 && (*ep)[len] == '=') {
            /* Found it; shift remainder + NULL over by one and update len. */
            memmove(ep, ep + 1,