git: 69c5f7b4ca36 - stable/14 - pkg: Fix Coverity warnings
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 26 Mar 2025 15:49:12 UTC
The branch stable/14 has been updated by ngie:
URL: https://cgit.FreeBSD.org/src/commit/?id=69c5f7b4ca368636a6a9fc7d8e0a99d4f1753e30
commit 69c5f7b4ca368636a6a9fc7d8e0a99d4f1753e30
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-01-16 15:09:58 +0000
Commit: Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2025-03-26 15:48:01 +0000
pkg: Fix Coverity warnings
- Fix allocation size in config_get_repositories().
- Fix a memory leak in read_conf_file().
- Avoid a null pointer dereference in an error path in
verify_pubsignature().
Fixes: e3b4a51580fc ("pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME")
Fixes: dc4581589a32 ("pkg: clean support for repositories")
(cherry picked from commit c1557708f1fae1bb9c8e23e3bbb2aa2b055e1211)
---
usr.sbin/pkg/config.c | 17 ++++++++++-------
usr.sbin/pkg/pkg.c | 2 +-
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c
index 16f7598fc745..44543f304657 100644
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -477,9 +477,9 @@ read_conf_file(const char *confpath, const char *requested_repo,
{
struct ucl_parser *p;
ucl_object_t *obj = NULL;
- const char *abi = pkg_get_myabi();
- char *major, *minor;
+ char *abi = pkg_get_myabi(), *major, *minor;
struct utsname uts;
+ int ret;
if (uname(&uts))
err(EXIT_FAILURE, "uname");
@@ -503,9 +503,9 @@ read_conf_file(const char *confpath, const char *requested_repo,
if (errno != ENOENT)
errx(EXIT_FAILURE, "Unable to parse configuration "
"file %s: %s", confpath, ucl_parser_get_error(p));
- ucl_parser_free(p);
/* no configuration present */
- return (1);
+ ret = 1;
+ goto out;
}
obj = ucl_parser_get_object(p);
@@ -518,13 +518,16 @@ read_conf_file(const char *confpath, const char *requested_repo,
else if (conftype == CONFFILE_REPO)
parse_repo_file(obj, requested_repo);
}
-
ucl_object_unref(obj);
+
+ ret = 0;
+out:
ucl_parser_free(p);
+ free(abi);
free(major);
free(minor);
- return (0);
+ return (ret);
}
static void
@@ -675,7 +678,7 @@ config_get_repositories(void)
{
if (STAILQ_EMPTY(&repositories)) {
/* Fall back to PACKAGESITE - deprecated - */
- struct repository *r = calloc(1, sizeof(r));
+ struct repository *r = calloc(1, sizeof(*r));
if (r == NULL)
err(EXIT_FAILURE, "calloc");
r->name = strdup("fallback");
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
index f19c93c6fbb5..305181699e4a 100644
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -669,7 +669,7 @@ verify_pubsignature(int fd_pkg, int fd_sig, struct repository *r)
pubkey = r->pubkey;
} else {
if (config_string(PUBKEY, &pubkey) != 0) {
- warnx("No CONFIG_PUBKEY defined for %s", r->name);
+ warnx("No CONFIG_PUBKEY defined");
goto cleanup;
}
}