develooper Front page | perl.perl5.porters | Postings from February 2015

[perl #123775] Args to 'system' not evaluated before forking, making $$ wrong

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
February 18, 2015 03:46
Subject:
[perl #123775] Args to 'system' not evaluated before forking, making $$ wrong
Message ID:
rt-4.0.18-30192-1424231213-1234.123775-15-0@perl.org
On Fri Feb 13 16:46:53 2015, LeonT wrote:
> On Sat, Feb 14, 2015 at 1:32 AM, Karl Williamson <public@khwilliamson.com>
> wrote:
> 
> > That is out-of-date.  All new code should use spaces exclusively.
> >
> 
> In that case, updated.

diff --git a/doio.c b/doio.c
index a63f2a2..dc4de86 100644
--- a/doio.c
+++ b/doio.c
@@ -1544,7 +1544,7 @@ Perl_do_aexec5(pTHX_ SV *really, SV **mark, SV **sp,
-		*a++ = SvPV_nolen_const(*mark);
+        *a++ = SvPV_nomg_nolen(*mark);
diff --git a/mathoms.c b/mathoms.c
index 2a65fb4..6ad8eb3 100644
--- a/mathoms.c
+++ b/mathoms.c
@@ -713,8 +713,12 @@ Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)

+    for (current = mark + 1; current <= SP; current++) {
+        SvGETMAGIC(*current);
+    }
diff --git a/pp_sys.c b/pp_sys.c
index e2f8edf..7e4ff61 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4259,6 +4259,12 @@ PP(pp_system)
+    else {
+        while (++MARK <= SP) {
+            (void)SvGETMAGIC(*MARK);      /* For get magic */
+        }
+        MARK = ORIGMARK;
+    }

Do we care about overloading?  It isn't triggered by SvGETMAGIC()
and will still be happening in the child.

Around Tue Feb 17 10:57:01 2015 Chris Wagner said:
> Tony indicated that system() does not use the fork() mechanism on Windows. So
> that might need a completely seperate patch. Or it could be unaffected.

system() on Win32 evaluates all of the arguments in the parent process and
(eventually) uses CreateProcess() to create the child.

The same is true of the newer list form pipe open implementation.

If you're seeing this problem on Windows, there's something unrelated going on.

Around Sat Feb 14 17:10:11 2015 Leon Timmermans said:
> On Sat, Feb 14, 2015 at 5:47 AM, Chris Wagner via RT <
perlbug-followup@perl.org> wrote:
> > +    skip 'Can\'t load POSIX' if not eval { require POSIX };
> +    if (my $child = open my $fh, '-|') { #parent
> +        my $pid = <$fh>;
> +        is($pid, $child, 'Pid is as expected in openpipe');
> +    }
> +    else { #child
> +        system $Perl, '-e', 'print $ARGV[0]', $$;
> +        POSIX::_exit(0);
> +    }
> </code>
>
> 
> I would still expect that to run into pseudothreads on Windows, but I
> haven't tested either version on Windows yet.

Windows doesn't handle "-|" with no arguments as a fork (it attempts to
run the "-" program), so it's not an issue.



---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123775

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About