This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix file-descriptor leak when pipes fail via taint checks:
authorIlya Zakharevich <ilya@math.berkeley.edu>
Thu, 26 Feb 1998 02:47:46 +0000 (21:47 -0500)
committerMalcolm Beattie <mbeattie@sable.ox.ac.uk>
Fri, 27 Feb 1998 15:26:45 +0000 (15:26 +0000)
Subject: [PATCH] Some patches went through cracks

p4raw-id: //depot/perl@593

os2/os2.c
util.c

index fe7f99b..f24c3af 100644 (file)
--- a/os2/os2.c
+++ b/os2/os2.c
@@ -620,8 +620,6 @@ char        *mode;
     PerlIO *res;
     SV *sv;
     
-    if (pipe(p) < 0)
-       return Nullfp;
     /* `this' is what we use in the parent, `that' in the child. */
     this = (*mode == 'w');
     that = !this;
@@ -629,6 +627,8 @@ char        *mode;
        taint_env();
        taint_proper("Insecure %s%s", "EXEC");
     }
+    if (pipe(p) < 0)
+       return Nullfp;
     /* Now we need to spawn the child. */
     newfd = dup(*mode == 'r');         /* Preserve std* */
     if (p[that] != (*mode == 'r')) {
diff --git a/util.c b/util.c
index 0dd9443..770aa29 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1855,14 +1855,14 @@ my_popen(char *cmd, char *mode)
        return my_syspopen(cmd,mode);
     }
 #endif 
-    if (PerlProc_pipe(p) < 0)
-       return Nullfp;
     This = (*mode == 'w');
     that = !This;
     if (doexec && tainting) {
        taint_env();
        taint_proper("Insecure %s%s", "EXEC");
     }
+    if (PerlProc_pipe(p) < 0)
+       return Nullfp;
     while ((pid = (doexec?vfork():fork())) < 0) {
        if (errno != EAGAIN) {
            PerlLIO_close(p[This]);