This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Safer environ iteration
authorMilosz Tanski <mtanski@gridapp.com>
Tue, 5 Aug 2008 18:33:02 +0000 (14:33 -0400)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Sun, 24 Aug 2008 15:23:41 +0000 (15:23 +0000)
From: "Milosz Tanski" <mtanski@gridapp.com>
Message-ID: <C0A5E31718FC064A91E9FD7BE2F081B1018A21D7@exchange.gridapp.com>

p4raw-id: //depot/perl@34225

perl.c

diff --git a/perl.c b/perl.c
index 0698996..e41ae96 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -4671,18 +4671,21 @@ S_init_postdump_symbols(pTHX_ register int argc, register char **argv, register
            environ[0] = NULL;
        }
        if (env) {
-         char *s;
+         char *s, *old_var;
          SV *sv;
          for (; *env; env++) {
-           if (!(s = strchr(*env,'=')) || s == *env)
+           old_var = *env;
+
+           if (!(s = strchr(old_var,'=')) || s == old_var)
                continue;
+
 #if defined(MSDOS) && !defined(DJGPP)
            *s = '\0';
-           (void)strupr(*env);
+           (void)strupr(old_var);
            *s = '=';
 #endif
            sv = newSVpv(s+1, 0);
-           (void)hv_store(hv, *env, s - *env, sv, 0);
+           (void)hv_store(hv, old_var, s - old_var, sv, 0);
            if (env_is_not_environ)
                mg_set(sv);
          }