Browse Source

libobs/util: Prevent leaking pipe file descriptors to subprocesses

Exeldro 1 year ago
parent
commit
65295eaf93
1 changed files with 6 additions and 0 deletions
  1. 6 0
      libobs/util/pipe-posix.c

+ 6 - 0
libobs/util/pipe-posix.c

@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <spawn.h>
+#include <fcntl.h>
 
 #include "bmem.h"
 #include "pipe.h"
@@ -66,6 +67,11 @@ os_process_pipe_t *os_process_pipe_create(const char *cmd_line,
 		return NULL;
 	}
 
+	fcntl(mainfds[0], F_SETFD, FD_CLOEXEC);
+	fcntl(mainfds[1], F_SETFD, FD_CLOEXEC);
+	fcntl(errfds[0], F_SETFD, FD_CLOEXEC);
+	fcntl(errfds[1], F_SETFD, FD_CLOEXEC);
+
 	if (process_pipe.read_pipe) {
 		posix_spawn_file_actions_addclose(&file_actions, mainfds[0]);
 		if (mainfds[1] != STDOUT_FILENO) {