rpms/xsane/devel xsane-0.995-close-fds.patch, 1.1, 1.2 xsane.spec, 1.57, 1.58
Nils Philippsen (nphilipp)
fedora-extras-commits at redhat.com
Fri Jul 18 14:13:45 UTC 2008
Author: nphilipp
Update of /cvs/pkgs/rpms/xsane/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv5500
Modified Files:
xsane-0.995-close-fds.patch xsane.spec
Log Message:
fix fd leak prevention (#455450)
xsane-0.995-close-fds.patch:
Index: xsane-0.995-close-fds.patch
===================================================================
RCS file: /cvs/pkgs/rpms/xsane/devel/xsane-0.995-close-fds.patch,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xsane-0.995-close-fds.patch 15 Jul 2008 15:53:42 -0000 1.1
+++ xsane-0.995-close-fds.patch 18 Jul 2008 14:13:01 -0000 1.2
@@ -1,29 +1,80 @@
diff -up xsane-0.995/src/xsane.c.close-fds xsane-0.995/src/xsane.c
--- xsane-0.995/src/xsane.c.close-fds 2007-09-28 17:24:56.000000000 +0200
-+++ xsane-0.995/src/xsane.c 2008-07-15 17:48:17.000000000 +0200
-@@ -3681,6 +3681,8 @@ static void xsane_show_doc_via_nsr(GtkWi
- char *arg[5];
- struct stat st;
- char netscape_lock_path[PATH_MAX];
-+ int open_max;
-+ int i;
++++ xsane-0.995/src/xsane.c 2008-07-18 16:10:30.000000000 +0200
+@@ -48,6 +48,8 @@
+
+ #include <sys/wait.h>
+
++#include <stdarg.h>
++
+ /* ---------------------------------------------------------------------------------------------------------------------- */
- DBG(DBG_proc, "xsane_show_doc_via_nsr(%s)\n", name);
+ struct option long_options[] =
+@@ -3673,6 +3675,41 @@ static void xsane_show_gpl(GtkWidget *wi
-@@ -3725,6 +3727,17 @@ static void xsane_show_doc_via_nsr(GtkWi
+ /* ---------------------------------------------------------------------------------------------------------------------- */
+
++static void xsane_close_fds_for_exec(signed int first_fd_to_leave_open, ...)
++{
++ int open_max;
++ signed int i;
++
++ va_list ap;
++ unsigned char *close_fds;
++
++ open_max = (int) sysconf (_SC_OPEN_MAX);
++
++ close_fds = malloc (open_max);
++
++ memset (close_fds, 1, open_max);
++
++ va_start (ap, first_fd_to_leave_open);
++
++ for (i = first_fd_to_leave_open; i >= 0; i = va_arg (ap, signed int)) {
++ if (i < open_max)
++ close_fds[i] = 0;
++ }
++
++ va_end (ap);
++
++ DBG(DBG_info, "closing unneeded file descriptors\n");
++
++ for (i = 0; i < open_max; i++) {
++ if (close_fds[i])
++ close (i);
++ }
++
++ free (close_fds);
++}
++
++/* ---------------------------------------------------------------------------------------------------------------------- */
++
+ static void xsane_show_doc_via_nsr(GtkWidget *widget, gpointer data) /* show via netscape remote */
+ {
+ char *name = (char *) data;
+@@ -3725,6 +3762,8 @@ static void xsane_show_doc_via_nsr(GtkWi
ipc_file = fdopen(xsane.ipc_pipefd[1], "w");
}
-+ open_max = (int) sysconf (_SC_OPEN_MAX);
++ xsane_close_fds_for_exec (1, 2, xsane.ipc_pipefd[1], -1);
+
-+ DBG(DBG_info, "closing unneeded file descriptors\n");
+ DBG(DBG_info, "trying to change user id for new subprocess:\n");
+ DBG(DBG_info, "old effective uid = %d\n", (int) geteuid());
+ setuid(getuid());
+@@ -3767,6 +3806,8 @@ static void xsane_show_doc_via_nsr(GtkWi
+ ipc_file = fdopen(xsane.ipc_pipefd[1], "w");
+ }
+
++ xsane_close_fds_for_exec (1, 2, xsane.ipc_pipefd[1], -1);
+
-+ /* leave stdin, stdout, stderr alone */
-+ for (i = 3; i < open_max; i++) {
-+ /* xsane.ipc_pipefd[0] is closed by now */
-+ if (i != xsane.ipc_pipefd[1])
-+ close (i);
-+ }
+ DBG(DBG_info, "trying to change user id for new subprocess:\n");
+ DBG(DBG_info, "old effective uid = %d\n", (int) geteuid());
+ setuid(getuid());
+@@ -3888,6 +3929,8 @@ static void xsane_show_doc(GtkWidget *wi
+ ipc_file = fdopen(xsane.ipc_pipefd[1], "w");
+ }
+
++ xsane_close_fds_for_exec (1, 2, xsane.ipc_pipefd[1], -1);
+
DBG(DBG_info, "trying to change user id for new subprocess:\n");
DBG(DBG_info, "old effective uid = %d\n", (int) geteuid());
Index: xsane.spec
===================================================================
RCS file: /cvs/pkgs/rpms/xsane/devel/xsane.spec,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- xsane.spec 15 Jul 2008 15:53:42 -0000 1.57
+++ xsane.spec 18 Jul 2008 14:13:01 -0000 1.58
@@ -3,7 +3,7 @@
Name: xsane
Summary: X Window System front-end for the SANE scanner interface
Version: 0.995
-Release: 4%{?dist}
+Release: 5%{?dist}
Source0: http://www.xsane.org/download/%{name}-%{version}.tar.gz
Source1: xsane.desktop
Source2: xsane.conf.in
@@ -107,6 +107,9 @@
%config(noreplace) %{_sysconfdir}/gimp/plugins.d/xsane.conf
%changelog
+* Fri Jul 18 2008 Nils Philippsen <nphilipp at redhat.com> - 0.995-5
+- fix fd leak prevention (#455450)
+
* Tue Jul 15 2008 Nils Philippsen <nphilipp at redhat.com> - 0.995-4
- don't leak file descriptors to help browser process (#455450)
More information about the scm-commits
mailing list