summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2008-05-28 20:01:22 (GMT)
committerColin Walters <walters@verbum.org>2008-05-28 20:01:22 (GMT)
commite2bc7232069b14b7299cb8b2eab436f60a232007 (patch)
tree40fa97042e54f01fcaa9921d6223209c1bb3962c
parentaf41f085c675d42d615050101e74f966931e5577 (diff)
Bug 15947: Close file descriptors before execing helper (Markus Rechberger)
* dbus/dbus-sysdeps-unix.c (_dbus_get_autolaunch_address): Close file descriptors before exec.
-rw-r--r--dbus/dbus-sysdeps-unix.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index 19858dd..a66d071 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -2848,7 +2848,10 @@ _dbus_get_autolaunch_address (DBusString *address,
if (pid == 0)
{
/* child process */
- int fd = open ("/dev/null", O_RDWR);
+ int maxfds;
+ int fd;
+
+ fd = open ("/dev/null", O_RDWR);
if (fd == -1)
/* huh?! can't open /dev/null? */
_exit (1);
@@ -2869,9 +2872,15 @@ _dbus_get_autolaunch_address (DBusString *address,
if (dup2 (errors_pipe[WRITE_END], 2) == -1)
_exit (1);
- close (fd);
- close (address_pipe[WRITE_END]);
- close (errors_pipe[WRITE_END]);
+ maxfds = sysconf (_SC_OPEN_MAX);
+ /* Pick something reasonable if for some reason sysconf
+ * says unlimited.
+ */
+ if (maxfds < 0)
+ maxfds = 1024;
+ /* close all inherited fds */
+ for (i = 3; i < maxfds; i++)
+ close (i);
execv (DBUS_BINDIR "/dbus-launch", argv);