[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    PATH corruption patch, take two
From:       Chip Turner <chip () zfx ! com>
Date:       1999-07-31 20:45:35
[Download RAW message or body]


Below is a new patch for the PATH corruption problems.  This one
solves the problem on my system (perl 5.00503, mod_perl 1.21, apache
1.36), and doesn't seem to leak memory.  I've changed the approach
that mod_perl takes in changing the environment variables since I
think that the underlying perl handling for magic variables (such as
ENV) has changed between various versions.  This uses the approach
that will hopefully work well -- it simply uses the perl interpreter
to change the variable in question.

If anyone feels adventurous, please give it a try.  Especially anyone
who has noticed a memory leak with the previous patch.

(begin patch)
diff -ur mod_perl-1.21/src/modules/perl/mod_perl.c mod_perl-1.21-fixed/src/modules/perl/mod_perl.c
--- mod_perl-1.21/src/modules/perl/mod_perl.c	Thu Jul  1 14:17:38 1999
+++ mod_perl-1.21-fixed/src/modules/perl/mod_perl.c	Sat Jul 31 16:05:31 1999
@@ -1574,7 +1574,7 @@
 
     for (i = 0; i < arr->nelts; ++i) {
 	if (!elts[i].key || !elts[i].val) continue;
-	mp_setenv(elts[i].key, elts[i].val);
+	mp_setenv(elts[i].key, elts[i].val, 0);
     }
     MP_TRACE_g(fprintf(stderr, "perl_setup_env...%d keys\n", i));
 }
diff -ur mod_perl-1.21/src/modules/perl/mod_perl.h mod_perl-1.21-fixed/src/modules/perl/mod_perl.h
--- mod_perl-1.21/src/modules/perl/mod_perl.h	Thu Jul  1 19:43:35 1999
+++ mod_perl-1.21-fixed/src/modules/perl/mod_perl.h	Sat Jul 31 16:01:49 1999
@@ -258,12 +258,6 @@
 
 #if 0
 
-#define mp_setenv(key, val) \
-mp_magic_setenv(key, val, 1)
-
-#define mp_SetEnv(key, val) \
-mp_magic_setenv(key, val, 0)
-
 #define mp_PassEnv(key) \
 { \
     char *val = getenv(key); \
@@ -272,18 +266,6 @@
 
 #else
 
-#define mp_setenv(key, val) \
-{ \
-    int klen = strlen(key); \
-    hv_store(GvHV(envgv), key, klen, newSVpv(val,0), FALSE); \
-    HV_SvTAINTED_on(GvHV(envgv), key, klen); \
-    my_setenv(key, val); \
-}
-
-#define mp_SetEnv(key, val) \
-    hv_store(GvHV(envgv), key, strlen(key), newSVpv(val,0), FALSE); \
-    my_setenv(key, val)
-
 #define mp_PassEnv(key) \
 { \
     char *val = getenv(key); \
@@ -1073,6 +1055,7 @@
 int mod_perl_seqno(SV *self, int inc);
 request_rec *perl_request_rec(request_rec *);
 void perl_setup_env(request_rec *r);
+void mp_setenv(char *, char *, int);
 SV  *perl_bless_request_rec(request_rec *); 
 void perl_set_request_rec(request_rec *); 
 void mod_perl_cleanup_av(void *data);
@@ -1110,7 +1093,6 @@
 int perl_load_startup_script(server_rec *s, pool *p, char *script, I32 my_warn);
 array_header *perl_cgi_env_init(request_rec *r);
 void perl_clear_env(void);
-void mp_magic_setenv(char *key, char *val, int is_tainted);
 void mod_perl_init_ids(void);
 int perl_eval_ok(server_rec *s);
 int perl_sv_is_http_code(SV *sv, int *status);
diff -ur mod_perl-1.21/src/modules/perl/perl_config.c mod_perl-1.21-fixed/src/modules/perl/perl_config.c
--- mod_perl-1.21/src/modules/perl/perl_config.c	Fri Jul  2 19:08:04 1999
+++ mod_perl-1.21-fixed/src/modules/perl/perl_config.c	Sat Jul 31 16:05:31 1999
@@ -171,7 +171,7 @@
 	for (i = 0; i < arr->nelts; ++i) {
 	    MP_TRACE_d(fprintf(stderr, "mod_perl_dir_env: %s=`%s'",
 			     elts[i].key, elts[i].val));
-	    mp_setenv(elts[i].key, elts[i].val);
+	    mp_setenv(elts[i].key, elts[i].val, 0);
 	}
 	MP_HASENV_off(cld); /* just doit once per-request */
     }
@@ -196,7 +196,7 @@
 
         if(val != NULL) {
 	    MP_TRACE_d(fprintf(stderr, "PerlPassEnv: `%s'=`%s'\n", key, val));
-	    mp_SetEnv(key,pstrdup(p,val));
+	    mp_setenv(key, pstrdup(p, val), 1);
         }
     }
 }    
@@ -682,7 +682,7 @@
     if(cmd->path == NULL) {
 	dPSRV(cmd->server); 
 	if(PERL_RUNNING()) { 
-	    mp_SetEnv(key,val);
+	    mp_setenv(key, val, 0);
 	} 
 	*(char **)push_array(cls->PerlPassEnv) = 
 	    pstrcat(cmd->pool, key, ":", val, NULL); 
diff -ur mod_perl-1.21/src/modules/perl/perl_util.c mod_perl-1.21-fixed/src/modules/perl/perl_util.c
--- mod_perl-1.21/src/modules/perl/perl_util.c	Thu Jul  1 18:07:20 1999
+++ mod_perl-1.21-fixed/src/modules/perl/perl_util.c	Sat Jul 31 16:19:09 1999
@@ -571,18 +571,6 @@
     return perl_eval_ok(s);
 } 
 
-void mp_magic_setenv(char *key, char *val, int is_tainted)
-{
-    int klen = strlen(key);
-    SV **ptr = hv_fetch(GvHV(envgv), key, klen, TRUE);
-    if (ptr) {
-	SvSetMagicSV(*ptr, newSVpv(val,0));
-	if (is_tainted) {
-	    SvTAINTED_on(*ptr);
-	}
-    }
-}
-
 array_header *perl_cgi_env_init(request_rec *r)
 {
     table *envtab = r->subprocess_env; 
@@ -849,3 +837,19 @@
 
 #endif
 
+void
+mp_setenv(char *key, char *val, int ignore_taint)
+{
+  SV *sv;
+  sv = sv_newmortal();
+
+  if (ignore_taint)	
+    sv_setpvf(sv, "$::ENV{%s} = '%s';", key, val);
+  else
+    sv_setpvf(sv, "$::ENV{%s} = '%s'; $::ENV{%s} =~ /(.*)/; $::ENV{%s} = $1;", key, val, key, key);    
+
+  perl_eval_sv(sv, G_DISCARD);
+}
+
+
+  

(end patch)

-- 
Chip Turner                   chip@ZFx.com
                              Programmer, ZFx, Inc.  www.zfx.com
                              PGP key available at wwwkeys.us.pgp.net

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic