[devel] [PATCH for apt 18/38] Apt-pipe: ensure mainloop function doesn't return uninitialized or garbage value
Aleksei Nikiforov
darktemplar на altlinux.org
Вт Дек 10 18:23:23 MSK 2019
Found via clang-static-analyzer
---
apt/cmdline/apt-pipe.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/apt/cmdline/apt-pipe.c b/apt/cmdline/apt-pipe.c
index 7bf1fc6..478eb70 100644
--- a/apt/cmdline/apt-pipe.c
+++ b/apt/cmdline/apt-pipe.c
@@ -155,7 +155,7 @@ static int send_reply(int sock, char *buf, ssize_t bufsize, int fd)
}
static int mainloop(int servsock) {
- int cl;
+ int cl = -1;
int done = 0;
char buf[65536];
@@ -173,7 +173,10 @@ static int mainloop(int servsock) {
if ((received = recv_query(cl, buf, sizeof(buf), &fd)) > 0 && fd != -1)
done = send_reply(cl, buf, received, fd);
if (!done)
+ {
close(cl);
+ cl = -1;
+ }
}
close(servsock);
@@ -254,7 +257,7 @@ static int daemonize()
/* cleanup */
aptpipe_fini();
unlink(APT_PIPE_PATH);
- if (fd)
+ if (fd >= 0)
write(fd, &i, sizeof(int));
exit(EXIT_SUCCESS);
}
--
2.24.0
Подробная информация о списке рассылки Devel