Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC::Open3 Does Not Re-Throw Exceptions #9765

Open
p5pRT opened this issue Jun 13, 2009 · 12 comments
Open

IPC::Open3 Does Not Re-Throw Exceptions #9765

p5pRT opened this issue Jun 13, 2009 · 12 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 13, 2009

Migrated from rt.perl.org#66572 (status was 'open')

Searchable as RT66572$

@p5pRT
Copy link
Author

p5pRT commented Jun 13, 2009

From @jawnsy

This is a bug report for perl from jonathan.i.yu@​gmail.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.


If using IPC​::Open3 under taintmode, the taint exceptions thrown by Perl's
system() call get caught but not re-thrown.

To reproduce this bug, you'll first need to taint your ENV{PATH} - I'm not
totally sure of the rules there, so I suppose you'll just need to add
something other than /usr/bin and /usr/local/bin to $ENV{PATH}.

If you try a normal system() call, then as expected, you get an exception
due to taint mode being on with an insecure $ENV{PATH}. So far so good.

If you use code like this​:

  use IPC​::Open3 'open3';

  my ($reader, $writer, $err);
  open3(undef, $reader, undef, 'pkg-config', '--libs', 'libjio');

You can check the return code of the child ($?) and you will be able to
tell that the child didn't exit cleanly (you get return code 29).
However, no exception is thrown.

If you continue, you can get the error from the STDOUT handle, rather
than the STDERR handle as one would expect​:

  print "Result​: ", <$reader>, "\n";

Gives this message​:

  Result​: Insecure $ENV{PATH} while running with -T switch at
  /usr/share/perl/5.10/IPC/Open3.pm line 168.

I think it would be most helpful if an exception was thrown to the caller of
open3, so that developers would know why the call failed (as it is a Perl
issue, not an issue calling pkg-config itself, since it's never actually
executed at all).

I submitted this bug with medium priority because presumably other Perl
exceptions are being caught and not propagated in the same manner, which
could make debugging other issues difficult too.

Thanks for writing a great module and maintaining my favourite language's
interpreter/compiler :-)



Flags​:
  category=library
  severity=medium


Site configuration information for perl 5.10.0​:

Configured by Debian Project at Sun May 3 21​:50​:46 UTC 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration​:
  Platform​:
  osname=linux, osvers=2.6.29.2-dsa-dl380-oldxeon, archname=i486-linux-gnu-thread-multi
  uname='linux murphy 2.6.29.2-dsa-dl380-oldxeon #2 smp mon apr 27 23​:13​:44 cest 2009 i686 gnulinux '
  config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.10.0 -Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=undef, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2 -g',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
  ccversion='', gccversion='4.3.3', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib /usr/lib64
  libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
  perllibs=-ldl -lm -lpthread -lc -lcrypt
  libc=/lib/libc-2.9.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0
  gnulibc_version='2.9'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl 5.10.0​:
  /etc/perl
  /usr/local/lib/perl/5.10.0
  /usr/local/share/perl/5.10.0
  /usr/lib/perl5
  /usr/share/perl5
  /usr/lib/perl/5.10
  /usr/share/perl/5.10
  /usr/local/lib/site_perl
  .


Environment for perl 5.10.0​:
  HOME=/home/jon
  LANG=en_CA.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=~/.bin​:/usr/local/bin​:/sbin​:/usr/bin​:/usr/sbin​:/usr/local/sbin​:/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2009

From @ikegami

On Sat, Jun 13, 2009 at 4​:23 PM, jonathan.i.yu@​gmail.com (via RT) <
perlbug-followup@​perl.org> wrote​:

# New Ticket Created by jonathan.i.yu@​gmail.com
# Please include the string​: [perl #66572]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=66572 >

This is a bug report for perl from jonathan.i.yu@​gmail.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
If using IPC​::Open3 under taintmode, the taint exceptions thrown by Perl's
system() call get caught but not re-thrown.

open3 throws an exception as a result, but it doesn't contain the message of
the original exception ("Insecure $ENV{PATH} while running with -T switch"),
outputting $! instead. This bug is in Win32-specific code. This is fixed in
patch2.

I also uncovered another bug. The error message contains IO​::Pipe as the
origin. ("open3​: IO​::Pipe​: Can't spawn-NOWAIT​: ...") while IO​::Pipe is not
involved. This is fixed in patch1.

Pardon the non-standard patch format and test format. I'm on borrowed time,
but I figured I'd get the ball rolling. Patched against 5.10.0's IPC​::Open3.
Test should be skipped on non-Windows systems.

Eric "ikegami" Brine

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2009

From @ikegami

patch1_test.pl

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2009

From @ikegami

patch1_to_open3_pm.diff
=    unless (@errs) {
=	$pid = eval { system 1, @_ }; # 1 == P_NOWAIT
-	push @errs, "IO::Pipe: Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;
+	push @errs, "Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;  # $Me will be prepended.
=    }

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2009

From @ikegami

patch2_test.pl

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2009

From @ikegami

patch2_to_open3_pm.diff
=    unless (@errs) {
=	$pid = eval { system 1, @_ }; # 1 == P_NOWAIT
-	push @errs, "Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;
+	push @errs, "Can't spawn-NOWAIT: $@" if !$pid;     # $Me will be prepended.
+	push @errs, "Can't spawn-NOWAIT: $!" if $pid < 0;  # $Me will be prepended.
=    }

@p5pRT
Copy link
Author

p5pRT commented Jun 15, 2009

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Feb 24, 2013

From @jkeenan

On Mon Jun 15 09​:25​:53 2009, ikegami@​adaelis.com wrote​:

On Sat, Jun 13, 2009 at 4​:23 PM, jonathan.i.yu@​gmail.com (via RT) <
perlbug-followup@​perl.org> wrote​:

# New Ticket Created by jonathan.i.yu@​gmail.com
# Please include the string​: [perl #66572]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=66572 >

This is a bug report for perl from jonathan.i.yu@​gmail.com,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
If using IPC​::Open3 under taintmode, the taint exceptions thrown by
Perl's
system() call get caught but not re-thrown.

open3 throws an exception as a result, but it doesn't contain the
message of
the original exception ("Insecure $ENV{PATH} while running with -T
switch"),
outputting $! instead. This bug is in Win32-specific code. This is
fixed in
patch2.

I also uncovered another bug. The error message contains IO​::Pipe as the
origin. ("open3​: IO​::Pipe​: Can't spawn-NOWAIT​: ...") while IO​::Pipe is not
involved. This is fixed in patch1.

Pardon the non-standard patch format and test format. I'm on borrowed
time,
but I figured I'd get the ball rolling. Patched against 5.10.0's
IPC​::Open3.
Test should be skipped on non-Windows systems.

Eric "ikegami" Brine

Eric,

If you think these issues still merit consideration (there's been no
further discussion in more than 3-1/2 years), could you re-submit the
patches in a more standard format, say, git-format-patch?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2013

From @ikegami

On Sun, Feb 24, 2013 at 5​:42 PM, James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

could you re-submit the patches in a more standard format, say,
git-format-patch?

Attached.

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2013

From @ikegami

0001-IPC-Open3-falsly-reports-some-errors-as-being-from-I.patch
From 3e93382fadf6ae53bdd688ea6a706855b6c20a8b Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Tue, 5 Mar 2013 15:10:48 -0500
Subject: [PATCH 1/3] IPC::Open3 falsly reports some errors as being from
 IO::Pipe

---
 ext/IPC-Open3/lib/IPC/Open3.pm |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ext/IPC-Open3/lib/IPC/Open3.pm b/ext/IPC-Open3/lib/IPC/Open3.pm
index 29612af..a0df61f 100644
--- a/ext/IPC-Open3/lib/IPC/Open3.pm
+++ b/ext/IPC-Open3/lib/IPC/Open3.pm
@@ -402,7 +402,7 @@ sub spawn_with_handles {
 	} else {
 	    $pid = eval { system 1, @_ }; # 1 == P_NOWAIT
 	}
-	push @errs, "IO::Pipe: Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;
+	push @errs, "Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;  # $Me will be prepended.
     }
 
     # Do this in reverse, so that STDERR is restored first:
-- 
1.7.9

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2013

From @ikegami

0002-Removed-IPC-Open3-s-useless-dependency-on-IO-Pipe.patch
From cbdcc6758ab3d141d3139e25b6cb0761a58f829d Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Tue, 5 Mar 2013 15:13:35 -0500
Subject: [PATCH 2/3] Removed IPC::Open3's useless dependency on IO::Pipe

---
 ext/IPC-Open3/lib/IPC/Open3.pm |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ext/IPC-Open3/lib/IPC/Open3.pm b/ext/IPC-Open3/lib/IPC/Open3.pm
index a0df61f..680345d 100644
--- a/ext/IPC-Open3/lib/IPC/Open3.pm
+++ b/ext/IPC-Open3/lib/IPC/Open3.pm
@@ -324,7 +324,6 @@ sub _open3 {
 		push @close, \*{$_->{parent}}, $_->{open_as};
 	    }
 	}
-	require IO::Pipe;
 	$kidpid = eval {
 	    spawn_with_handles(\@handles, \@close, @_);
 	};
@@ -357,6 +356,7 @@ sub spawn_with_handles {
     my $close_in_child = shift;
     my ($fd, $pid, @saved_fh, $saved, %saved, @errs);
 
+    require IO::Handle;
     foreach $fd (@$fds) {
 	$fd->{tmp_copy} = IO::Handle->new_from_fd($fd->{handle}, $fd->{mode});
 	$saved{fileno $fd->{handle}} = $fd->{tmp_copy} if $fd->{tmp_copy};
-- 
1.7.9

@p5pRT
Copy link
Author

p5pRT commented Mar 5, 2013

From @ikegami

0003-IPC-Open3-s-open3-looked-for-error-messages-in-on-ex.patch
From e833642c7645f637f609c99a8d7c79437aa45b9a Mon Sep 17 00:00:00 2001
From: Eric Brine <ikegami@adaelis.com>
Date: Tue, 5 Mar 2013 15:16:51 -0500
Subject: [PATCH 3/3] IPC::Open3's open3 looked for error messages in $! on
 exception

---
 ext/IPC-Open3/lib/IPC/Open3.pm |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/ext/IPC-Open3/lib/IPC/Open3.pm b/ext/IPC-Open3/lib/IPC/Open3.pm
index 680345d..de1ac06 100644
--- a/ext/IPC-Open3/lib/IPC/Open3.pm
+++ b/ext/IPC-Open3/lib/IPC/Open3.pm
@@ -402,7 +402,8 @@ sub spawn_with_handles {
 	} else {
 	    $pid = eval { system 1, @_ }; # 1 == P_NOWAIT
 	}
-	push @errs, "Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;  # $Me will be prepended.
+	push @errs, "Can't spawn-NOWAIT: $@" if !$pid;     # $Me will be prepended.
+	push @errs, "Can't spawn-NOWAIT: $!" if $pid < 0;  # $Me will be prepended.
     }
 
     # Do this in reverse, so that STDERR is restored first:
-- 
1.7.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants