summaryrefslogtreecommitdiff
path: root/src/ipcpd
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2023-07-13 17:58:51 +0200
committerSander Vrijders <sander@ouroboros.rocks>2023-07-31 14:06:16 +0200
commit26fe256c14c5d7b98682c6497e733c4a2dde9921 (patch)
treec67ef25b5c7aebc4148bf538c2af6c6b127c3823 /src/ipcpd
parentbe3daaf2b7c64f7636981abb0f055aac758e0186 (diff)
downloadouroboros-26fe256c14c5d7b98682c6497e733c4a2dde9921.tar.gz
ouroboros-26fe256c14c5d7b98682c6497e733c4a2dde9921.zip
ipcpd: Fix leaked filedescriptors in ipcpd-udp
Found by GCC static analyzer. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/ipcpd')
-rw-r--r--src/ipcpd/udp/main.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/ipcpd/udp/main.c b/src/ipcpd/udp/main.c
index b2170e0b..ee7e2f8f 100644
--- a/src/ipcpd/udp/main.c
+++ b/src/ipcpd/udp/main.c
@@ -712,7 +712,7 @@ static int udp_ipcp_bootstrap(const struct ipcp_config * conf)
/* NOTE: Disgusted with this crap */
static int ddns_send(char * cmd)
{
- pid_t pid = -1;
+ pid_t pid;
int wstatus;
int pipe_fd[2];
char * argv[] = {NSUPDATE_EXEC, 0};
@@ -726,6 +726,8 @@ static int ddns_send(char * cmd)
pid = fork();
if (pid == -1) {
log_err("Failed to fork.");
+ close(pipe_fd[0]);
+ close(pipe_fd[1]);
return -1;
}
@@ -733,6 +735,8 @@ static int ddns_send(char * cmd)
close(pipe_fd[1]);
dup2(pipe_fd[0], 0);
execve(argv[0], &argv[0], envp);
+ log_err("Failed to execute: %s", strerror(errno));
+ exit(1);
}
close(pipe_fd[0]);
@@ -779,7 +783,9 @@ static uint32_t ddns_resolve(char * name,
pid = fork();
if (pid == -1) {
log_err("Failed to fork.");
- return 0;
+ close(pipe_fd[0]);
+ close(pipe_fd[1]);
+ return -1;
}
if (pid == 0) {
@@ -789,6 +795,8 @@ static uint32_t ddns_resolve(char * name,
close(pipe_fd[0]);
dup2(pipe_fd[1], 1);
execve(argv[0], &argv[0], envp);
+ log_err("Failed to execute: %s", strerror(errno));
+ exit(1);
}
close(pipe_fd[1]);