
Michael.Schroeder at informatik
Nov 11, 2004, 6:54 AM
Post #1 of 12
(1929 views)
Permalink
|
|
SuSE's perl safe_putenf diff
|
|
Hi Porters, here's a patch from SuSE's perl-5.8.5. It changes the putenv handling in a way so that PERL_USE_SAFE_PUTENV is defined for applications that embedded perl. It does this by adding a global variable "Perl_use_safe_putenv" that defaults to 1 but is cleared by perlmain. The reasoning is this: Perl applications know that they must call perl's putenv, so it is safe to use it in this case. If perl is just a module in another application (e.g. mod_perl), this assumption no longer holds, so we have to switch to the safe system putenv in that case. Cheers, Michael. --- ./mg.c.orig 2004-06-30 19:51:44.000000000 +0000 +++ ./mg.c 2004-07-28 12:25:14.520609864 +0000 @@ -1046,6 +1046,8 @@ # endif { # ifndef PERL_USE_SAFE_PUTENV + extern int Perl_use_safe_putenv; + if (!Perl_use_safe_putenv) { I32 i; if (environ == PL_origenviron) @@ -1053,6 +1055,7 @@ else for (i = 0; environ[i]; i++) safesysfree(environ[i]); + } # endif /* PERL_USE_SAFE_PUTENV */ environ[0] = Nullch; --- ./miniperlmain.c.orig 2003-05-04 09:40:14.000000000 +0000 +++ ./miniperlmain.c 2004-07-28 12:25:14.522609256 +0000 @@ -39,6 +39,10 @@ main(int argc, char **argv, char **env) { int exitstatus; +#ifndef PERL_USE_SAFE_PUTENV + extern int Perl_use_safe_putenv; + Perl_use_safe_putenv = 0; +#endif /* PERL_USE_SAFE_PUTENV */ #ifdef PERL_GLOBAL_STRUCT #define PERLVAR(var,type) /**/ --- ./perl.c.orig 2004-06-23 10:35:46.000000000 +0000 +++ ./perl.c 2004-07-28 12:25:14.533605909 +0000 @@ -81,6 +81,10 @@ char *nw_get_sitelib(const char *pl); #endif +#if !defined(PERL_USE_SAFE_PUTENV) +int Perl_use_safe_putenv = 1; +#endif + /* XXX If this causes problems, set i_unistd=undef in the hint file. */ #ifdef I_UNISTD #include <unistd.h> @@ -590,7 +594,7 @@ */ #ifndef PERL_MICRO #if defined(USE_ENVIRON_ARRAY) && !defined(PERL_USE_SAFE_PUTENV) - if (environ != PL_origenviron + if (environ != PL_origenviron && !Perl_use_safe_putenv #ifdef USE_ITHREADS /* only main thread can free environ[0] contents */ && PL_curinterp == aTHX --- ./util.c.orig 2004-03-22 19:54:24.000000000 +0000 +++ ./util.c 2004-07-28 12:25:14.553599825 +0000 @@ -1462,6 +1462,8 @@ #endif { #ifndef PERL_USE_SAFE_PUTENV + extern int Perl_use_safe_putenv; + if (!Perl_use_safe_putenv) { /* most putenv()s leak, so we manipulate environ directly */ register I32 i=setenv_getix(nam); /* where does it go? */ int nlen, vlen; @@ -1502,8 +1504,8 @@ environ[i] = (char*)safesysmalloc((nlen+vlen+2) * sizeof(char)); /* all that work just for this */ my_setenv_format(environ[i], nam, nlen, val, vlen); - -#else /* PERL_USE_SAFE_PUTENV */ + } else { +# endif # if defined(__CYGWIN__) || defined( EPOC) setenv(nam, val, 1); # else @@ -1518,7 +1520,9 @@ my_setenv_format(new_env, nam, nlen, val, vlen); (void)putenv(new_env); # endif /* __CYGWIN__ */ -#endif /* PERL_USE_SAFE_PUTENV */ +#ifndef PERL_USE_SAFE_PUTENV + } +#endif } }
|