41a6c3
--- a/server/util_script.c  2017/10/11 14:41:00 1811830
41a6c3
+++ b/server/util_script.c  2017/10/11 14:48:55 1811831
41a6c3
@@ -92,9 +92,21 @@
41a6c3
     }
41a6c3
 }
41a6c3
 
41a6c3
-static void env2env(apr_table_t *table, const char *name)
41a6c3
+/* Sets variable @name in table @dest from r->subprocess_env if
41a6c3
+ * available, else from the environment, else from @fallback if
41a6c3
+ * non-NULL. */
41a6c3
+static void env2env(apr_table_t *dest, request_rec *r,
41a6c3
+                    const char *name, const char *fallback)
41a6c3
 {
41a6c3
-    add_unless_null(table, name, getenv(name));
41a6c3
+    const char *val;
41a6c3
+
41a6c3
+    val = apr_table_get(r->subprocess_env, name);
41a6c3
+    if (!val)
41a6c3
+        val = apr_pstrdup(r->pool, getenv(name));
41a6c3
+    if (!val)
41a6c3
+        val = apr_pstrdup(r->pool, fallback);
41a6c3
+    if (val)
41a6c3
+        apr_table_addn(dest, name, val);
41a6c3
 }
41a6c3
 
41a6c3
 AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
41a6c3
@@ -211,37 +223,29 @@
41a6c3
             add_unless_null(e, http2env(r, hdrs[i].key), hdrs[i].val);
41a6c3
     }
41a6c3
 
41a6c3
-    env_temp = apr_table_get(r->subprocess_env, "PATH");
41a6c3
-    if (env_temp == NULL) {
41a6c3
-        env_temp = getenv("PATH");
41a6c3
-    }
41a6c3
-    if (env_temp == NULL) {
41a6c3
-        env_temp = DEFAULT_PATH;
41a6c3
-    }
41a6c3
-    apr_table_addn(e, "PATH", apr_pstrdup(r->pool, env_temp));
41a6c3
-
41a6c3
+    env2env(e, r, "PATH", DEFAULT_PATH);
41a6c3
 #if defined(WIN32)
41a6c3
-    env2env(e, "SystemRoot");
41a6c3
-    env2env(e, "COMSPEC");
41a6c3
-    env2env(e, "PATHEXT");
41a6c3
-    env2env(e, "WINDIR");
41a6c3
+    env2env(e, r, "SystemRoot", NULL);
41a6c3
+    env2env(e, r, "COMSPEC", NULL);
41a6c3
+    env2env(e, r, "PATHEXT", NULL);
41a6c3
+    env2env(e, r, "WINDIR", NULL);
41a6c3
 #elif defined(OS2)
41a6c3
-    env2env(e, "COMSPEC");
41a6c3
-    env2env(e, "ETC");
41a6c3
-    env2env(e, "DPATH");
41a6c3
-    env2env(e, "PERLLIB_PREFIX");
41a6c3
+    env2env(e, r, "COMSPEC", NULL);
41a6c3
+    env2env(e, r, "ETC", NULL);
41a6c3
+    env2env(e, r, "DPATH", NULL);
41a6c3
+    env2env(e, r, "PERLLIB_PREFIX", NULL);
41a6c3
 #elif defined(BEOS)
41a6c3
-    env2env(e, "LIBRARY_PATH");
41a6c3
+    env2env(e, r, "LIBRARY_PATH", NULL);
41a6c3
 #elif defined(DARWIN)
41a6c3
-    env2env(e, "DYLD_LIBRARY_PATH");
41a6c3
+    env2env(e, r, "DYLD_LIBRARY_PATH", NULL);
41a6c3
 #elif defined(_AIX)
41a6c3
-    env2env(e, "LIBPATH");
41a6c3
+    env2env(e, r, "LIBPATH", NULL);
41a6c3
 #elif defined(__HPUX__)
41a6c3
     /* HPUX PARISC 2.0W knows both, otherwise redundancy is harmless */
41a6c3
-    env2env(e, "SHLIB_PATH");
41a6c3
-    env2env(e, "LD_LIBRARY_PATH");
41a6c3
+    env2env(e, r, "SHLIB_PATH", NULL);
41a6c3
+    env2env(e, r, "LD_LIBRARY_PATH", NULL);
41a6c3
 #else /* Some Unix */
41a6c3
-    env2env(e, "LD_LIBRARY_PATH");
41a6c3
+    env2env(e, r, "LD_LIBRARY_PATH", NULL);
41a6c3
 #endif
41a6c3
 
41a6c3
     apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));