From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Tue, 10 Dec 2019 18:23:23 +0300 Message-Id: <20191210152343.33867-19-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210152343.33867-1-darktemplar@altlinux.org> References: <20191210152343.33867-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt 18/38] Apt-pipe: ensure mainloop function doesn't return uninitialized or garbage value X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Dec 2019 15:25:07 -0000 Archived-At: List-Archive: List-Post: 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