]> granicus.if.org Git - mutt/commitdiff
Pass envlist to filter children too. (closes #3922)
authorKevin McCarthy <kevin@8t8.us>
Sat, 18 Mar 2017 20:48:02 +0000 (13:48 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sat, 18 Mar 2017 20:48:02 +0000 (13:48 -0700)
The new setenv patch neglected to pass the envlist for filters too.

Unfortunately, the filter code was already set up to pass COLUMNS to
children, so it needed to be changed to add this to the envlist
instead.

Factor out mutt_envlist_set() from the parse_setenv() function, which
the filter code can then use to set COLUMNS after forking.

filter.c
init.c
protos.h
system.c

index 0e94d249fa84f57e76ece2e8d5a565e5dafc6e1b..a10dcd2a6c6906908c68f3cb308fff99e7eb0a49 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -122,10 +122,10 @@ mutt_create_filter_fd (const char *cmd, FILE **in, FILE **out, FILE **err,
     if (MuttIndexWindow && (MuttIndexWindow->cols > 0))
     {
       snprintf (columns, sizeof (columns), "%d", MuttIndexWindow->cols);
-      setenv ("COLUMNS", columns, 1);
+      mutt_envlist_set ("COLUMNS", columns);
     }
 
-    execl (EXECSHELL, "sh", "-c", cmd, NULL);
+    execle (EXECSHELL, "sh", "-c", cmd, NULL, mutt_envlist ());
     _exit (127);
   }
   else if (thepid == -1)
diff --git a/init.c b/init.c
index 7c0f179a0c4c4865bad66e7d2b77afd3a5683010..7e027c66e2f372431ea5a558d55ea03dfc4a8dad 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1845,11 +1845,57 @@ static int check_charset (struct option_t *opt, const char *val)
   return rc;
 }
 
+char **mutt_envlist (void)
+{
+  return envlist;
+}
+
+/* Helper function for parse_setenv().
+ * It's broken out because some other parts of mutt (filter.c) need
+ * to set/overwrite environment variables in envlist before execing.
+ */
+void mutt_envlist_set (const char *name, const char *value)
+{
+  char **envp = envlist;
+  char work[LONG_STRING];
+  int count, len;
+
+  len = mutt_strlen (name);
+
+  /* Look for current slot to overwrite */
+  count = 0;
+  while (envp && *envp)
+  {
+    if (!mutt_strncmp (name, *envp, len) && (*envp)[len] == '=')
+    {
+      FREE (envp);     /* __FREE_CHECKED__ */
+      break;
+    }
+    envp++;
+    count++;
+  }
+
+  /* Format var=value string */
+  snprintf (work, sizeof(work), "%s=%s", NONULL (name), NONULL (value));
+
+  /* If slot found, overwrite */
+  if (*envp)
+    *envp = safe_strdup (work);
+
+  /* If not found, add new slot */
+  else
+  {
+    *envp = safe_strdup (work);
+    count++;
+    safe_realloc (&envlist, sizeof(char *) * (count + 1));
+    envlist[count] = NULL;
+  }
+}
+
 static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
 {
   int query, unset, len;
-  char work[LONG_STRING];
-  char **save, **envp = envlist;
+  char *name, **save, **envp = envlist;
   int count = 0;
 
   query = 0;
@@ -1924,6 +1970,8 @@ static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
     return -1;
   }
 
+  /* set variable */
+
   if (*s->dptr == '=')
   {
     s->dptr++;
@@ -1936,38 +1984,10 @@ static int parse_setenv(BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
     return -1;
   }
 
-  /* Look for current slot to overwrite */
-  count = 0;
-  while (envp && *envp)
-  {
-    if (!mutt_strncmp (tmp->data, *envp, len) && (*envp)[len] == '=')
-    {
-      FREE (envp);     /* __FREE_CHECKED__ */
-      break;
-    }
-    envp++;
-    count++;
-  }
-
-  /* Format var=value string */
-  strfcpy (work, tmp->data, sizeof(work));
-  len = strlen (work);
-  work[len++] = '=';
+  name = safe_strdup (tmp->data);
   mutt_extract_token (tmp, s, 0);
-  strfcpy (&work[len], tmp->data, sizeof(work)-len);
-
-  /* If slot found, overwrite */
-  if (*envp)
-    *envp = safe_strdup (work);
-
-  /* If not found, add new slot */
-  else
-  {
-    *envp = safe_strdup (work);
-    count++;
-    safe_realloc (&envlist, sizeof(char *) * (count + 1));
-    envlist[count] = NULL;
-  }
+  mutt_envlist_set (name, tmp->data);
+  FREE (&name);
 
   return 0;
 }
index c43b49cd22968bf3fc0eed8f100c2613f346aa24..37bfe6df6bed16f8ec609be0e88e580f9b4efcc6 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -185,6 +185,8 @@ void mutt_display_sanitize (char *);
 void mutt_edit_content_type (HEADER *, BODY *, FILE *);
 void mutt_edit_file (const char *, const char *);
 void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t);
+char **mutt_envlist (void);
+void mutt_envlist_set (const char *name, const char *value);
 int mutt_filter_unprintable (char **);
 int mutt_label_message (HEADER *);
 void mutt_make_label_hash (CONTEXT *);
index 97dc2a8e79732c47398e0d9d8f5115f10f6da44d..a0aa4dac0db379f0e4f604bc93cb6186cd571c0f 100644 (file)
--- a/system.c
+++ b/system.c
@@ -32,8 +32,6 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-extern char **envlist;
-
 int _mutt_system (const char *cmd, int flags)
 {
   int rc = -1;
@@ -116,7 +114,7 @@ int _mutt_system (const char *cmd, int flags)
     sigaction (SIGTSTP, &act, NULL);
     sigaction (SIGCONT, &act, NULL);
 
-    execle (EXECSHELL, "sh", "-c", cmd, NULL, envlist);
+    execle (EXECSHELL, "sh", "-c", cmd, NULL, mutt_envlist ());
     _exit (127); /* execl error */
   }
   else if (thepid != -1)