[PATCH 1/3] aptcc: sanitize file descriptor handling

Colin Watson cjwatson at canonical.com
Mon Jan 24 06:14:10 PST 2011


Make sure that apt always has a stdout fd.  Running apt with no fd 1 is
invalid, and causes any maintainer script that writes to stdout (not an
uncommon practice) to die with EBADF.

Close pipes we don't need before running apt.
---
 backends/aptcc/apt.cpp |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/backends/aptcc/apt.cpp b/backends/aptcc/apt.cpp
index 55c9a62..78935a1 100644
--- a/backends/aptcc/apt.cpp
+++ b/backends/aptcc/apt.cpp
@@ -1783,9 +1783,11 @@ cout << "How odd.. The sizes didn't match, email apt at packages.debian.org";
 			close(writeToChildFD[0]);
 			_exit(1);
 		}
+		close(writeToChildFD[0]);
 
-		// close Forked stdout and the read end of the pipe
-		close(1);
+		// close pipes we don't need
+		close(readFromChildFD[0]);
+		close(writeToChildFD[1]);
 
 		// Change the locale to not get libapt localization
 		setlocale(LC_ALL, "C");
@@ -1814,10 +1816,7 @@ cout << "How odd.. The sizes didn't match, email apt at packages.debian.org";
 		// dump errors into cerr (pass it to the parent process)
 		_error->DumpErrors();
 
-		close(readFromChildFD[0]);
-		close(writeToChildFD[1]);
 		close(readFromChildFD[1]);
-		close(writeToChildFD[0]);
 
 		_exit(res);
 	}
-- 
1.7.2.3


--svZFHVx8/dhPCe52
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-Set-client-locale-to-LC_MESSAGES-rather-than-LC_ALL.patch"



More information about the PackageKit mailing list