summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2008-05-28 16:01:22 -0400
committerColin Walters <walters@verbum.org>2008-05-28 16:01:22 -0400
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 19858dd3..a66d0710 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -2848,7 +2848,10 @@ _dbus_get_autolaunch_address (DBusString *address,
2848 if (pid == 0) 2848 if (pid == 0)
2849 { 2849 {
2850 /* child process */ 2850 /* child process */
2851 int fd = open ("/dev/null", O_RDWR); 2851 int maxfds;
2852 int fd;
2853
2854 fd = open ("/dev/null", O_RDWR);
2852 if (fd == -1) 2855 if (fd == -1)
2853 /* huh?! can't open /dev/null? */ 2856 /* huh?! can't open /dev/null? */
2854 _exit (1); 2857 _exit (1);
@@ -2869,9 +2872,15 @@ _dbus_get_autolaunch_address (DBusString *address,
2869 if (dup2 (errors_pipe[WRITE_END], 2) == -1) 2872 if (dup2 (errors_pipe[WRITE_END], 2) == -1)
2870 _exit (1); 2873 _exit (1);
2871 2874
2872 close (fd); 2875 maxfds = sysconf (_SC_OPEN_MAX);
2873 close (address_pipe[WRITE_END]); 2876 /* Pick something reasonable if for some reason sysconf
2874 close (errors_pipe[WRITE_END]); 2877 * says unlimited.
2878 */
2879 if (maxfds < 0)
2880 maxfds = 1024;
2881 /* close all inherited fds */
2882 for (i = 3; i < maxfds; i++)
2883 close (i);
2875 2884
2876 execv (DBUS_BINDIR "/dbus-launch", argv); 2885 execv (DBUS_BINDIR "/dbus-launch", argv);
2877 2886