e7cad98
--- nut-2.7.4/common/parseconf.c.cloexec	2018-12-07 15:56:22.989381441 -0800
e7cad98
+++ nut-2.7.4/common/parseconf.c	2018-12-07 16:48:33.912337591 -0800
e7cad98
@@ -83,6 +83,7 @@
e7cad98
 #include <stdlib.h>
e7cad98
 #include <string.h>	
e7cad98
 #include <unistd.h>
e7cad98
+#include <fcntl.h>
e7cad98
 
e7cad98
 #include "parseconf.h"
e7cad98
 
e7cad98
@@ -443,6 +444,9 @@
e7cad98
 		return 0;
e7cad98
 	}
e7cad98
 
e7cad98
+	/* prevent fd leaking to child processes */
e7cad98
+	fcntl(fileno(ctx->f), F_SETFD, FD_CLOEXEC);
e7cad98
+
e7cad98
 	return 1;	/* OK */
e7cad98
 }
e7cad98
 
e7cad98
--- nut-2.7.4/clients/upsmon.c.cloexec	2018-12-07 16:22:42.185376803 -0800
e7cad98
+++ nut-2.7.4/clients/upsmon.c	2018-12-07 17:18:44.662093479 -0800
e7cad98
@@ -24,6 +24,8 @@
e7cad98
 #include <sys/stat.h>
e7cad98
 #include <sys/wait.h>
e7cad98
 #include <sys/socket.h>
e7cad98
+#include <unistd.h>
e7cad98
+#include <fcntl.h>
e7cad98
 
e7cad98
 #include "upsclient.h"
e7cad98
 #include "upsmon.h"
e7cad98
@@ -1432,6 +1434,9 @@
e7cad98
 	/* we're definitely connected now */
e7cad98
 	setflag(&ups->status, ST_CONNECTED);
e7cad98
 
e7cad98
+	/* prevent connection leaking to NOTIFYCMD */
e7cad98
+	fcntl(upscli_fd(&ups->conn), F_SETFD, FD_CLOEXEC);
e7cad98
+
e7cad98
 	/* now try to authenticate to upsd */
e7cad98
 
e7cad98
 	ret = do_upsd_auth(ups);
e7cad98
@@ -1715,6 +1720,9 @@
e7cad98
 	}
e7cad98
 
e7cad98
 	close(pipefd[0]);
e7cad98
+
e7cad98
+	/* prevent pipe leaking to NOTIFYCMD */
e7cad98
+	fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
e7cad98
 }
e7cad98
 
e7cad98
 static void delete_ups(utype_t *target)
e7cad98
--- nut-2.7.4/clients/upssched.c.cloexec	2018-12-07 17:09:13.081914570 -0800
e7cad98
+++ nut-2.7.4/clients/upssched.c	2018-12-07 18:28:54.380512191 -0800
e7cad98
@@ -46,6 +46,8 @@
e7cad98
 #include <sys/socket.h>
e7cad98
 #include <sys/un.h>
e7cad98
 #include <netinet/in.h>
e7cad98
+#include <unistd.h>
e7cad98
+#include <fcntl.h>
e7cad98
 
e7cad98
 #include "upssched.h"
e7cad98
 #include "timehead.h"
e7cad98
@@ -297,6 +299,9 @@
e7cad98
 	if (ret < 0)
e7cad98
 		fatal_with_errno(EXIT_FAILURE, "listen(%d, %d) failed", fd, US_LISTEN_BACKLOG);
e7cad98
 
e7cad98
+	/* don't leak socket to CMDSCRIPT */
e7cad98
+	fcntl(fd, F_SETFD, FD_CLOEXEC);
e7cad98
+
e7cad98
 	return fd;
e7cad98
 }
e7cad98
 
e7cad98
@@ -370,6 +375,9 @@
e7cad98
 		return;
e7cad98
 	}
e7cad98
 
e7cad98
+	/* don't leak connection to CMDSCRIPT */
e7cad98
+	fcntl(acc, F_SETFD, FD_CLOEXEC);
e7cad98
+
e7cad98
 	/* enable nonblocking I/O */
e7cad98
 
e7cad98
 	ret = fcntl(acc, F_GETFL, 0);