[dpkg] 103/187: Dpkg::IPC: Defer filehandle closures in spawn() to avoid double-close

Reiner Herrmann reiner at reiner-h.de
Sun Nov 6 12:46:30 UTC 2016


This is an automated email from the git hooks/post-receive script.

deki-guest pushed a commit to branch master
in repository dpkg.

commit 05d5a6590879078c9992b9e8a8a07371413858e1
Author: Guillem Jover <guillem at debian.org>
Date:   Fri Oct 14 23:58:59 2016 +0200

    Dpkg::IPC: Defer filehandle closures in spawn() to avoid double-close
    
    When the caller passes the same filehandle for STDIN, STDOUT or STDERR,
    the code will try to close the same filehandle more than once, producing
    an error. Defer the closures to the end using the same close_in_child
    array already used for other filehandles.
    
    Closes: #839905, #840293
---
 debian/changelog    | 2 ++
 scripts/Dpkg/IPC.pm | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 74a27e6..4386bcf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -58,6 +58,8 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
     - Fix reproducible source package support in Dpkg::Source::Archive, by
       sorting the tar contents with --sort=name.
     - Prefix private Dpkg::Source::Package::* functions with _.
+    - Defer filehandle closures in Dpkg::IPC::spawn() to avoid double-close.
+      Closes: #839905, #840293
   * Packaging:
     - Add liblocale-gettext-perl to libdpkg-perl Recommends.
     - Wrap and document dependency relationships.
diff --git a/scripts/Dpkg/IPC.pm b/scripts/Dpkg/IPC.pm
index 5172540..3dfbde9 100644
--- a/scripts/Dpkg/IPC.pm
+++ b/scripts/Dpkg/IPC.pm
@@ -282,7 +282,8 @@ sub spawn {
 	} elsif ($opts{from_handle}) {
 	    open(STDIN, '<&', $opts{from_handle})
 		or syserr(g_('reopen stdin'));
-	    close($opts{from_handle}); # has been duped, can be closed
+	    # has been duped, can be closed
+	    push @{$opts{close_in_child}}, $opts{from_handle};
 	}
 	# Redirect STDOUT if needed
 	if ($opts{to_file}) {
@@ -291,7 +292,8 @@ sub spawn {
 	} elsif ($opts{to_handle}) {
 	    open(STDOUT, '>&', $opts{to_handle})
 		or syserr(g_('reopen stdout'));
-	    close($opts{to_handle}); # has been duped, can be closed
+	    # has been duped, can be closed
+	    push @{$opts{close_in_child}}, $opts{to_handle};
 	}
 	# Redirect STDERR if needed
 	if ($opts{error_to_file}) {
@@ -300,7 +302,8 @@ sub spawn {
 	} elsif ($opts{error_to_handle}) {
 	    open(STDERR, '>&', $opts{error_to_handle})
 	        or syserr(g_('reopen stdout'));
-	    close($opts{error_to_handle}); # has been duped, can be closed
+	    # has been duped, can be closed
+	    push @{$opts{close_in_child}}, $opts{error_to_handle};
 	}
 	# Close some inherited filehandles
 	close($_) foreach (@{$opts{close_in_child}});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list