]> granicus.if.org Git - mutt/commitdiff
Fix setenv overwriting to not truncate the envlist. (see #3922)
authorKevin McCarthy <kevin@8t8.us>
Mon, 20 Mar 2017 17:16:03 +0000 (10:16 -0700)
committerKevin McCarthy <kevin@8t8.us>
Mon, 20 Mar 2017 17:16:03 +0000 (10:16 -0700)
The refactor in 2b9c40f13e13 exposed a bug I hadn't noticed.  The
match loop performed a FREE() on the slot.  Then, below, it was
checking if (*envp) to see whether it was overwriting or creating a
new slot.  However, FREE() nulls out *envp.  This would end up
truncating the envlist just after the set slot!

Move the free down, using a mutt_str_replace(), when overwriting the
slot.

init.c

diff --git a/init.c b/init.c
index 953e5c8bf3377c671bfcceb919c5cf17ee54b149..d9eed5bc77c0b8f0740f602e37b51cdb6fa226c7 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1867,10 +1867,7 @@ void mutt_envlist_set (const char *name, const char *value)
   while (envp && *envp)
   {
     if (!mutt_strncmp (name, *envp, len) && (*envp)[len] == '=')
-    {
-      FREE (envp);     /* __FREE_CHECKED__ */
       break;
-    }
     envp++;
     count++;
   }
@@ -1880,7 +1877,7 @@ void mutt_envlist_set (const char *name, const char *value)
 
   /* If slot found, overwrite */
   if (envp && *envp)
-    *envp = safe_strdup (work);
+    mutt_str_replace (envp, work);
 
   /* If not found, add new slot */
   else