file: avoid closing stdio descriptors in rpc_file_exec_run
authorJo-Philipp Wich <jo@mein.io>
Fri, 21 Dec 2018 08:30:19 +0000 (09:30 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 21 Dec 2018 08:30:19 +0000 (09:30 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
file.c

diff --git a/file.c b/file.c
index 23deb73e2470f6ccbe3f074db79a9930e200a324..016f264033e6f1a8181c7d53db06b84277d5281b 100644 (file)
--- a/file.c
+++ b/file.c
@@ -590,6 +590,13 @@ rpc_file_exec_epipe_state_cb(struct ustream *s)
                rpc_file_exec_reply(c, UBUS_STATUS_OK);
 }
 
+static void
+rpc_fdclose(int fd)
+{
+       if (fd > 2)
+               close(fd);
+}
+
 static int
 rpc_file_exec_run(const char *cmd,
                   const struct blob_attr *arg, const struct blob_attr *env,
@@ -639,11 +646,11 @@ rpc_file_exec_run(const char *cmd,
                dup2(opipe[1], 1);
                dup2(epipe[1], 2);
 
-               close(devnull);
-               close(opipe[0]);
-               close(opipe[1]);
-               close(epipe[0]);
-               close(epipe[1]);
+               rpc_fdclose(devnull);
+               rpc_fdclose(opipe[0]);
+               rpc_fdclose(opipe[1]);
+               rpc_fdclose(epipe[0]);
+               rpc_fdclose(epipe[1]);
 
                arglen = 2;
                args = malloc(sizeof(char *) * arglen);