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
#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 */
#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 */
# endif
{
# ifndef PERL_USE_SAFE_PUTENV
+ if (!PL_use_safe_putenv) {
I32 i;
if (environ == PL_origenviron)
else
for (i = 0; environ[i]; i++)
safesysfree(environ[i]);
+ }
# endif /* PERL_USE_SAFE_PUTENV */
environ[0] = Nullch;
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) /**/
*/
#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
#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 */
PERLVARI(Gcsighandlerp, Sighandler_t, &Perl_csighandler) /* Pointer to C-level sighandler */
#endif
+#ifndef PERL_USE_SAFE_PUTENV
+PERLVARI(Guse_safe_putenv, int, 1)
+#endif
#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;
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
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
}
}