summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-12-21 09:30:19 +0100
committerJo-Philipp Wich <jo@mein.io>2020-05-26 16:21:13 +0200
commit313964caa8342a2f63258f2c98b714cd2de4fb52 (patch)
tree3f7049503b2ebacabc72bd3828936e312066f428
parentcd09c5f3512c9d6dca0c0ed7144cb1a994672454 (diff)
downloadrpcd-313964caa8342a2f63258f2c98b714cd2de4fb52.tar.gz
file: avoid closing stdio descriptors in rpc_file_exec_run
Signed-off-by: Jo-Philipp Wich <jo@mein.io> (cherry picked from commit ffaa6132cb968fbf9532bdb9cbd0780073b9e7cd)
-rw-r--r--file.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/file.c b/file.c
index 23deb73..016f264 100644
--- 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);