From nobody Thu Feb 16 20:37:37 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHmwK3BLqz3rVTQ; Thu, 16 Feb 2023 20:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHmwK2k8dz3wG5; Thu, 16 Feb 2023 20:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676579857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ydtejTkSLfsO92GbNB3rG2ZKvQG6rAedFZKOx9yFjEs=; b=knkDMFs+8fMTuyxeiu6Lxl1ul4PzdHGcdXGbpVoWJnLUrzfIv2TFqvdW1rGbF/WvTOGMU1 17TAhvQbp74KFnjOq4Cyf2d/H2sGsnHU8sDasEnNND8Fi/5SmB675Nlv0I6xwTAxv2sk+Q 10A8ULNBt6Qe0LHMr9YzFdjZ58+4FJ1cLc9DjDwKqAqvK22UBXOlo9RNPl3oK9GzoVAK79 hOAi/WPo/pO/T7vUDVekOkaT+30UtbQL8YLjYB7AvD25PxPRWo2KJq3iZElm2JnO8AIygo WCWxelOr6NKbIVSb6wGs4XwFTSpByu2JcJnRq6CN0Hcg5ME+p+erepAa5gNxFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676579857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ydtejTkSLfsO92GbNB3rG2ZKvQG6rAedFZKOx9yFjEs=; b=a0H8bVRDe2+HfvXuvjXSTDsW6MK8rXEV4ZT1hScgrD72xZNLIH8OnPCHOx0eDA2fkYsseL Oqm0ZNx8KK5p8MREaGdlcC21gZh3xot+sx6mVnGi4GujZpy9hwESt1v5+EdiQ4DZTUeb/A zF8fiAaQAC8HlzzCFAuWXGBtaQr9JSHdnIH3pkLJLlGxMKaSRSE03Z3tWbH50pE5wbIbu6 8KyslRJDNu//ISWR9+1lSAlQH4Hhbz3cYJAktwQDFnxXsZcDf6CMc2qeXNRScBvbLCS7ML kl8szHdQ2PPw+cwnJuQHLHfmdKwNf1/W8liRJ7P37Qv2NDdYIWI/UUEtFdTkJA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676579857; a=rsa-sha256; cv=none; b=W11NBoxXiTRYTLC3UdpVLhEX7syroPyoy8xUQAd+8T/YofTnQmpYESimStPRJb43uSfTeS ZyiBAMekPtc6AiCTH3Z6LLhJFQiX8KLJUxDZhiwJ/nx8B+OVTjgv9egVa3gN62BwcY3Cy2 0gssLJS35xgXppedOxHQw+GEY/QYqyt6AMzD03YXWAzYcA9qoe3kNzXX8bXCcVD0ig2yyH FsTY80rquQo7fUQIn5m0h/z4de+cDq6UhP5DgNeuSYP6u/ss6jiv8/LrD9W5PqvpJLpy+o zX/tyyXS4slsKO5HlwNvd65JolWGfzmI32RUwHXt1Q3B1KxVqhmRI15eYMoLHA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PHmwK1k9czHfC; Thu, 16 Feb 2023 20:37:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31GKbbfB002562; Thu, 16 Feb 2023 20:37:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31GKbbAY002561; Thu, 16 Feb 2023 20:37:37 GMT (envelope-from git) Date: Thu, 16 Feb 2023 20:37:37 GMT Message-Id: <202302162037.31GKbbAY002561@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: c04ad15ca7db - main - config: address a number of Coverity issues List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c04ad15ca7dbe9034b274e404edc0bcf6a5300e0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=c04ad15ca7dbe9034b274e404edc0bcf6a5300e0 commit c04ad15ca7dbe9034b274e404edc0bcf6a5300e0 Author: Kyle Evans AuthorDate: 2023-02-16 20:36:17 +0000 Commit: Kyle Evans CommitDate: 2023-02-16 20:37:06 +0000 config: address a number of Coverity issues Highlights: - Various memory leaks - FILE* leaks - `tsize` in moveifchanged() is only needed if !changed, and `from_sb` is only valid if !changed. - Simplify trivially true expression - Sanity check elfdump size output (+ fix variable sizes) (des@) CID: 1471167, 1006391, 1505333, 1505275, 1505349, 1505306, 1505232 Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D38643 --- usr.sbin/config/lang.l | 2 ++ usr.sbin/config/main.cc | 10 ++++++---- usr.sbin/config/mkoptions.cc | 20 +++++++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l index ed0b2aa794b3..243b66666d0e 100644 --- a/usr.sbin/config/lang.l +++ b/usr.sbin/config/lang.l @@ -297,6 +297,8 @@ include(const char *fname, int ateof) return (-1); } cfgfile_add(fnamebuf == NULL ? fname : fnamebuf); + free(fnamebuf); + in = malloc(sizeof(*in)); assert(in != NULL); in->in_prev = inclp; diff --git a/usr.sbin/config/main.cc b/usr.sbin/config/main.cc index 66a071401183..f6c99e32c594 100644 --- a/usr.sbin/config/main.cc +++ b/usr.sbin/config/main.cc @@ -616,9 +616,9 @@ moveifchanged(const char *from_name, const char *to_name) if (!changed && from_sb.st_size != to_sb.st_size) changed++; - tsize = (size_t)from_sb.st_size; - if (!changed) { + tsize = (size_t)from_sb.st_size; + p = (char *)mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0); if (p == MAP_FAILED) @@ -736,7 +736,7 @@ kernconfdump(const char *file) struct stat st; FILE *fp, *pp; int error, osz, r; - unsigned int i, off, size, t1, t2, align; + size_t i, off, size, t1, t2, align; char *cmd, *o; r = open(file, O_RDONLY); @@ -765,8 +765,10 @@ kernconfdump(const char *file) free(cmd); (void)fread(o, osz, 1, pp); pclose(pp); - r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align); + r = sscanf(o, "%zu%zu%zu%zu%zu", &off, &size, &t1, &t2, &align); free(o); + if (size > SIZE_MAX - off || off + size > (size_t)st.st_size) + errx(EXIT_FAILURE, "%s: incoherent ELF headers", file); if (r != 5) errx(EXIT_FAILURE, "File %s doesn't contain configuration " "file. Either unsupported, or not compiled with " diff --git a/usr.sbin/config/mkoptions.cc b/usr.sbin/config/mkoptions.cc index 134c09c2d074..1ffb9722af8b 100644 --- a/usr.sbin/config/mkoptions.cc +++ b/usr.sbin/config/mkoptions.cc @@ -263,7 +263,7 @@ do_option(char *name) if (op == NULL) err(EXIT_FAILURE, "calloc"); op->op_name = ns(name); - op->op_value = value ? ns(value) : NULL; + op->op_value = ns(value); SLIST_INSERT_HEAD(&op_head, op, op_next); } @@ -383,8 +383,10 @@ read_option_file(const char *fname, int flags) } optname = ns(wd); wd = get_word(fp); - if (wd.eof()) - return (1); + if (wd.eof()) { + free(optname); + break; + } if (wd.eol()) { if (flags) { fprintf(stderr, "%s: compat file requires two" @@ -399,10 +401,18 @@ read_option_file(const char *fname, int flags) } else { val = ns(wd); } - if (flags == 0) + + if (flags == 0) { + /* + * insert_option takes possession of `optname` in the + * new option instead of making yet another copy. + */ insert_option(fname, optname, val); - else + } else { update_option(optname, val, flags); + free(optname); + optname = NULL; + } } (void)fclose(fp); return (1);