summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schroeder <Michael.Schroeder@informatik.uni-erlangen.de>2004-11-11 16:54:43 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-11-17 10:11:20 +0000
commit50acdf951a03f778010b5632532ec99bfa7c4f6a (patch)
treec02916c2de2c738a64bdd1ac0207abd339ab86d1
parentbe9a9b1dd000aab30f25ebe003679f9814da62af (diff)
downloadperl-50acdf951a03f778010b5632532ec99bfa7c4f6a.tar.gz
SuSE's perl safe_putenf diff
Message-ID: <20041111145443.GA1854@immd4.informatik.uni-erlangen.de> slightly reworked to make the PL_use_safe_putenv variable fit in the current framework. This patch turns on the use of safe putenv for any application that embeds a perl interpreter. p4raw-id: //depot/perl@23507
-rw-r--r--embedvar.h2
-rw-r--r--mg.c2
-rw-r--r--miniperlmain.c3
-rw-r--r--perl.c2
-rw-r--r--perlapi.h2
-rw-r--r--perlvars.h3
-rw-r--r--util.c9
7 files changed, 19 insertions, 4 deletions
diff --git a/embedvar.h b/embedvar.h
index 47056d28b6..3e7d7f67d2 100644
--- a/embedvar.h
+++ b/embedvar.h
@@ -900,6 +900,7 @@
#define PL_sigfpe_saved (PL_Vars.Gsigfpe_saved)
#define PL_sv_placeholder (PL_Vars.Gsv_placeholder)
#define PL_thr_key (PL_Vars.Gthr_key)
+#define PL_use_safe_putenv (PL_Vars.Guse_safe_putenv)
#else /* !PERL_GLOBAL_STRUCT */
@@ -917,6 +918,7 @@
#define PL_Gsigfpe_saved PL_sigfpe_saved
#define PL_Gsv_placeholder PL_sv_placeholder
#define PL_Gthr_key PL_thr_key
+#define PL_Guse_safe_putenv PL_use_safe_putenv
#endif /* PERL_GLOBAL_STRUCT */
diff --git a/mg.c b/mg.c
index d8e17dd877..b5a9290923 100644
--- a/mg.c
+++ b/mg.c
@@ -1082,6 +1082,7 @@ Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
# endif
{
# ifndef PERL_USE_SAFE_PUTENV
+ if (!PL_use_safe_putenv) {
I32 i;
if (environ == PL_origenviron)
@@ -1089,6 +1090,7 @@ Perl_magic_clear_all_env(pTHX_ SV *sv, MAGIC *mg)
else
for (i = 0; environ[i]; i++)
safesysfree(environ[i]);
+ }
# endif /* PERL_USE_SAFE_PUTENV */
environ[0] = Nullch;
diff --git a/miniperlmain.c b/miniperlmain.c
index 286ce9137a..94a6d5b4f0 100644
--- a/miniperlmain.c
+++ b/miniperlmain.c
@@ -48,6 +48,9 @@ int
main(int argc, char **argv, char **env)
{
int exitstatus;
+#ifndef PERL_USE_SAFE_PUTENV
+ PL_use_safe_putenv = 0;
+#endif /* PERL_USE_SAFE_PUTENV */
#ifdef PERL_GLOBAL_STRUCT
#define PERLVAR(var,type) /**/
diff --git a/perl.c b/perl.c
index 1525df222d..03187a38ca 100644
--- a/perl.c
+++ b/perl.c
@@ -471,7 +471,7 @@ perl_destruct(pTHXx)
*/
#ifndef PERL_MICRO
#if defined(USE_ENVIRON_ARRAY) && !defined(PERL_USE_SAFE_PUTENV)
- if (environ != PL_origenviron
+ if (environ != PL_origenviron && !PL_use_safe_putenv
#ifdef USE_ITHREADS
/* only main thread can free environ[0] contents */
&& PL_curinterp == aTHX
diff --git a/perlapi.h b/perlapi.h
index b74d1dbb10..dddb24fc31 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -946,6 +946,8 @@ END_EXTERN_C
#define PL_sv_placeholder (*Perl_Gsv_placeholder_ptr(NULL))
#undef PL_thr_key
#define PL_thr_key (*Perl_Gthr_key_ptr(NULL))
+#undef PL_use_safe_putenv
+#define PL_use_safe_putenv (*Perl_Guse_safe_putenv_ptr(NULL))
#endif /* !PERL_CORE */
#endif /* MULTIPLICITY */
diff --git a/perlvars.h b/perlvars.h
index 9cc8a2f57e..d57cb28b9d 100644
--- a/perlvars.h
+++ b/perlvars.h
@@ -69,3 +69,6 @@ PERLVAR(Gsv_placeholder, SV)
PERLVARI(Gcsighandlerp, Sighandler_t, &Perl_csighandler) /* Pointer to C-level sighandler */
#endif
+#ifndef PERL_USE_SAFE_PUTENV
+PERLVARI(Guse_safe_putenv, int, 1)
+#endif
diff --git a/util.c b/util.c
index 52319d32fb..9a90549ae6 100644
--- a/util.c
+++ b/util.c
@@ -1372,6 +1372,7 @@ Perl_my_setenv(pTHX_ char *nam, char *val)
#endif
{
#ifndef PERL_USE_SAFE_PUTENV
+ if (!PL_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;
@@ -1412,8 +1413,8 @@ Perl_my_setenv(pTHX_ char *nam, char *val)
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
@@ -1428,7 +1429,9 @@ Perl_my_setenv(pTHX_ char *nam, char *val)
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
}
}