You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2017/10/11 14:48:55 UTC

svn commit: r1811831 - /httpd/httpd/trunk/server/util_script.c

Author: jorton
Date: Wed Oct 11 14:48:55 2017
New Revision: 1811831

URL: http://svn.apache.org/viewvc?rev=1811831&view=rev
Log:
* server/util_script.c (ap_add_common_vars): Allow mod_env to override
  all system path environment variables, not just PATH.  (The
  behaviour for PATH alone was changed in r965679 for PR 43906.)

Modified:
    httpd/httpd/trunk/server/util_script.c

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



Re: svn commit: r1811831 - /httpd/httpd/trunk/server/util_script.c

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Apr 9, 2018 at 10:07 AM, Joe Orton <jo...@redhat.com> wrote:
> On Thu, Apr 05, 2018 at 01:38:05PM +0200, Yann Ylavic wrote:
>> On Wed, Oct 11, 2017 at 4:48 PM,  <jo...@apache.org> wrote:
>> > Author: jorton
>> > Date: Wed Oct 11 14:48:55 2017
>> > New Revision: 1811831
>> >
>> > URL: http://svn.apache.org/viewvc?rev=1811831&view=rev
>> > Log:
>> > * server/util_script.c (ap_add_common_vars): Allow mod_env to override
>> >   all system path environment variables, not just PATH.  (The
>> >   behaviour for PATH alone was changed in r965679 for PR 43906.)
>>
>> Since SetEnv* are usable from htaccess, don't we open a risky door here?
>
> If we allow control over PATH (which we do already) I am struggling to
> imagine how it would be worse to allow control of anything other env
> var.

LD_LIBRARY_PATH (and alike) look even more "fun" to play with, possibly.
Whilst applications may not need/use PATH, they can't do much about
LD_LIBRARY_PATH.

PR 43906 states that one can already overwrite LD_LIBRARY_PATH, it's
not the case anymore today I think (w/o this commit).

>
> Can you think of a scenario where it would be a problem?

Custom .so in /path/to/my/htaccess-ed/htdocs for instance which would
be loaded underneath the app (with the same rights).
Although I agree that PATH may already be an issue, so it all depends
on the "trust" given to htaccess files I suppose...
How about a directive to control that? yes it sucks, but...


Regards,
Yann.

Re: svn commit: r1811831 - /httpd/httpd/trunk/server/util_script.c

Posted by Joe Orton <jo...@redhat.com>.
On Thu, Apr 05, 2018 at 01:38:05PM +0200, Yann Ylavic wrote:
> On Wed, Oct 11, 2017 at 4:48 PM,  <jo...@apache.org> wrote:
> > Author: jorton
> > Date: Wed Oct 11 14:48:55 2017
> > New Revision: 1811831
> >
> > URL: http://svn.apache.org/viewvc?rev=1811831&view=rev
> > Log:
> > * server/util_script.c (ap_add_common_vars): Allow mod_env to override
> >   all system path environment variables, not just PATH.  (The
> >   behaviour for PATH alone was changed in r965679 for PR 43906.)
> 
> Since SetEnv* are usable from htaccess, don't we open a risky door here?

If we allow control over PATH (which we do already) I am struggling to 
imagine how it would be worse to allow control of anything other env 
var.

Can you think of a scenario where it would be a problem?

Regards, Joe

Re: svn commit: r1811831 - /httpd/httpd/trunk/server/util_script.c

Posted by Yann Ylavic <yl...@gmail.com>.
On Wed, Oct 11, 2017 at 4:48 PM,  <jo...@apache.org> wrote:
> Author: jorton
> Date: Wed Oct 11 14:48:55 2017
> New Revision: 1811831
>
> URL: http://svn.apache.org/viewvc?rev=1811831&view=rev
> Log:
> * server/util_script.c (ap_add_common_vars): Allow mod_env to override
>   all system path environment variables, not just PATH.  (The
>   behaviour for PATH alone was changed in r965679 for PR 43906.)

Since SetEnv* are usable from htaccess, don't we open a risky door here?


Regards,
Yann.