|
|
6d3471 |
From 6dee7eadd1b7352ec503ea04fa1639d4a93f370b Mon Sep 17 00:00:00 2001
|
|
|
6d3471 |
From: Nils Philippsen <nils@redhat.com>
|
|
|
6d3471 |
Date: Thu, 16 Aug 2012 11:18:31 +0200
|
|
|
6d3471 |
Subject: [PATCH] patch: close-fds
|
|
|
6d3471 |
|
|
|
6d3471 |
Squashed commit of the following:
|
|
|
6d3471 |
|
|
|
6d3471 |
commit 4fdedd3a8b66fb42b2d4dde62df28c78571c1c5d
|
|
|
6d3471 |
Author: Nils Philippsen <nils@redhat.com>
|
|
|
6d3471 |
Date: Fri Nov 19 12:15:58 2010 +0100
|
|
|
6d3471 |
|
|
|
6d3471 |
don't leak file descriptors to help browser process (#455450)
|
|
|
6d3471 |
---
|
|
|
6d3471 |
src/xsane.c | 43 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
6d3471 |
1 file changed, 43 insertions(+)
|
|
|
6d3471 |
|
|
|
6d3471 |
diff --git a/src/xsane.c b/src/xsane.c
|
|
|
6d3471 |
index 775610e..1c5d61d 100644
|
|
|
6d3471 |
--- a/src/xsane.c
|
|
|
6d3471 |
+++ b/src/xsane.c
|
|
|
6d3471 |
@@ -48,6 +48,8 @@
|
|
|
6d3471 |
|
|
|
6d3471 |
#include <sys/wait.h>
|
|
|
6d3471 |
|
|
|
6d3471 |
+#include <stdarg.h>
|
|
|
6d3471 |
+
|
|
|
6d3471 |
/* ---------------------------------------------------------------------------------------------------------------------- */
|
|
|
6d3471 |
|
|
|
6d3471 |
struct option long_options[] =
|
|
|
6d3471 |
@@ -3684,6 +3686,41 @@ static void xsane_show_gpl(GtkWidget *widget, gpointer data)
|
|
|
6d3471 |
|
|
|
6d3471 |
/* ---------------------------------------------------------------------------------------------------------------------- */
|
|
|
6d3471 |
|
|
|
6d3471 |
+static void xsane_close_fds_for_exec(signed int first_fd_to_leave_open, ...)
|
|
|
6d3471 |
+{
|
|
|
6d3471 |
+ int open_max;
|
|
|
6d3471 |
+ signed int i;
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ va_list ap;
|
|
|
6d3471 |
+ unsigned char *close_fds;
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ open_max = (int) sysconf (_SC_OPEN_MAX);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ close_fds = malloc (open_max);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ memset (close_fds, 1, open_max);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ va_start (ap, first_fd_to_leave_open);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ for (i = first_fd_to_leave_open; i >= 0; i = va_arg (ap, signed int)) {
|
|
|
6d3471 |
+ if (i < open_max)
|
|
|
6d3471 |
+ close_fds[i] = 0;
|
|
|
6d3471 |
+ }
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ va_end (ap);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ DBG(DBG_info, "closing unneeded file descriptors\n");
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ for (i = 0; i < open_max; i++) {
|
|
|
6d3471 |
+ if (close_fds[i])
|
|
|
6d3471 |
+ close (i);
|
|
|
6d3471 |
+ }
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+ free (close_fds);
|
|
|
6d3471 |
+}
|
|
|
6d3471 |
+
|
|
|
6d3471 |
+/* ---------------------------------------------------------------------------------------------------------------------- */
|
|
|
6d3471 |
+
|
|
|
6d3471 |
static void xsane_show_doc_via_nsr(GtkWidget *widget, gpointer data) /* show via netscape remote */
|
|
|
6d3471 |
{
|
|
|
6d3471 |
char *name = (char *) data;
|
|
|
6d3471 |
@@ -3736,6 +3773,8 @@ static void xsane_show_doc_via_nsr(GtkWidget *widget, gpointer data) /* show via
|
|
|
6d3471 |
ipc_file = fdopen(xsane.ipc_pipefd[1], "w");
|
|
|
6d3471 |
}
|
|
|
6d3471 |
|
|
|
6d3471 |
+ xsane_close_fds_for_exec (1, 2, xsane.ipc_pipefd[1], -1);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
DBG(DBG_info, "trying to change user id for new subprocess:\n");
|
|
|
6d3471 |
DBG(DBG_info, "old effective uid = %d\n", (int) geteuid());
|
|
|
6d3471 |
setuid(getuid());
|
|
|
6d3471 |
@@ -3778,6 +3817,8 @@ static void xsane_show_doc_via_nsr(GtkWidget *widget, gpointer data) /* show via
|
|
|
6d3471 |
ipc_file = fdopen(xsane.ipc_pipefd[1], "w");
|
|
|
6d3471 |
}
|
|
|
6d3471 |
|
|
|
6d3471 |
+ xsane_close_fds_for_exec (1, 2, xsane.ipc_pipefd[1], -1);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
DBG(DBG_info, "trying to change user id for new subprocess:\n");
|
|
|
6d3471 |
DBG(DBG_info, "old effective uid = %d\n", (int) geteuid());
|
|
|
6d3471 |
setuid(getuid());
|
|
|
6d3471 |
@@ -3899,6 +3940,8 @@ static void xsane_show_doc(GtkWidget *widget, gpointer data)
|
|
|
6d3471 |
ipc_file = fdopen(xsane.ipc_pipefd[1], "w");
|
|
|
6d3471 |
}
|
|
|
6d3471 |
|
|
|
6d3471 |
+ xsane_close_fds_for_exec (1, 2, xsane.ipc_pipefd[1], -1);
|
|
|
6d3471 |
+
|
|
|
6d3471 |
DBG(DBG_info, "trying to change user id for new subprocess:\n");
|
|
|
6d3471 |
DBG(DBG_info, "old effective uid = %d\n", (int) geteuid());
|
|
|
6d3471 |
setuid(getuid());
|
|
|
6d3471 |
--
|
|
|
6d3471 |
1.7.11.4
|
|
|
6d3471 |
|