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=ham autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Tue, 10 Dec 2019 18:23:21 +0300 Message-Id: <20191210152343.33867-17-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 16/38] Don't access uninitialized data 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:24:57 -0000 Archived-At: List-Archive: List-Post: Found via clang-static-analyzer --- apt/methods/http.cc | 25 ++++++++++++++----------- apt/tools/genpkglist.cc | 12 +++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apt/methods/http.cc b/apt/methods/http.cc index 6b5c2a5..c9a37de 100644 --- a/apt/methods/http.cc +++ b/apt/methods/http.cc @@ -844,19 +844,22 @@ bool HttpMethod::ServerDie(ServerState *Srv) { unsigned int LErrno = errno; - // Dump the buffer to the file - if (Srv->State == ServerState::Data) + if (File != 0) { - SetNonBlock(File->Fd(),false); - while (Srv->In.WriteSpace() == true) + // Dump the buffer to the file + if (Srv->State == ServerState::Data) { - auto FileFD = MethodFd::FromFd(File->Fd()); - if (Srv->In.Write(FileFD) == false) - return _error->Errno("write",_("Error writing to the file")); - - // Done - if (Srv->In.IsLimit() == true) - return true; + SetNonBlock(File->Fd(),false); + while (Srv->In.WriteSpace() == true) + { + auto FileFD = MethodFd::FromFd(File->Fd()); + if (Srv->In.Write(FileFD) == false) + return _error->Errno("write",_("Error writing to the file")); + + // Done + if (Srv->In.IsLimit() == true) + return true; + } } } diff --git a/apt/tools/genpkglist.cc b/apt/tools/genpkglist.cc index b354a08..2350f6d 100644 --- a/apt/tools/genpkglist.cc +++ b/apt/tools/genpkglist.cc @@ -488,8 +488,6 @@ int scandir(const char * dir, struct dirent *** namelist, } } - v[i] = NULL; - if (errno != 0) { save = errno; @@ -504,9 +502,13 @@ int scandir(const char * dir, struct dirent *** namelist, (void) closedir (dp); errno = save; - /* Sort the list if we have a comparison function to sort with. */ - if (cmp != NULL) - qsort (v, i, sizeof (struct dirent *), cmp); + if (v != NULL) + { + v[i] = NULL; + /* Sort the list if we have a comparison function to sort with. */ + if (cmp != NULL) + qsort (v, i, sizeof (struct dirent *), cmp); + } *namelist = v; return i; -- 2.24.0