Change 16331 by gsar@onru on 2002/05/02 06:39:27

        fix race condition in my_popen(): parent may dup2() into an fd
        that got opened by another thread because it closes it
        beforehand; instead, let the dup2() itself close the fd

Affected files ...

.... //depot/maint-5.6/perl/util.c#40 edit

Differences ...

==== //depot/maint-5.6/perl/util.c#40 (text) ====
Index: perl/util.c
--- perl/util.c.~1~     Thu May  2 00:45:07 2002
+++ perl/util.c Thu May  2 00:45:07 2002
@@ -2357,7 +2357,6 @@
 #undef THAT
 #define THIS that
 #define THAT This
-       PerlLIO_close(p[THAT]);
        if (did_pipes) {
            PerlLIO_close(pp[0]);
 #if defined(HAS_FCNTL) && defined(F_SETFD)
@@ -2367,7 +2366,11 @@
        if (p[THIS] != (*mode == 'r')) {
            PerlLIO_dup2(p[THIS], *mode == 'r');
            PerlLIO_close(p[THIS]);
+           if (p[THAT] != (*mode == 'r'))      /* if dup2() didn't close it */
+               PerlLIO_close(p[THAT]);
        }
+       else
+           PerlLIO_close(p[THAT]);
 #ifndef OS2
        if (doexec) {
 #if !defined(HAS_FCNTL) || !defined(F_SETFD)
@@ -2394,7 +2397,6 @@
 #undef THAT
     }
     do_execfree();     /* free any memory malloced by child on vfork */
-    PerlLIO_close(p[that]);
     if (did_pipes)
        PerlLIO_close(pp[1]);
     if (p[that] < p[This]) {
@@ -2402,6 +2404,9 @@
        PerlLIO_close(p[This]);
        p[This] = p[that];
     }
+    else
+       PerlLIO_close(p[that]);
+
     LOCK_FDPID_MUTEX;
     sv = *av_fetch(PL_fdpid,p[This],TRUE);
     UNLOCK_FDPID_MUTEX;
End of Patch.

Reply via email to