From: Kevin McCarthy Date: Mon, 20 Mar 2017 17:16:03 +0000 (-0700) Subject: Fix setenv overwriting to not truncate the envlist. (see #3922) X-Git-Tag: mutt-1-8-1-rel~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f3de81717fde6775aca35b09485753b571ed6d6;p=mutt Fix setenv overwriting to not truncate the envlist. (see #3922) 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. --- diff --git a/init.c b/init.c index 953e5c8b..d9eed5bc 100644 --- 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