pkg: make sure the repositories have at least an url

While here, factorize code to free the repository structure
This commit is contained in:
Baptiste Daroussin 2025-01-15 09:06:55 +01:00
parent 7befd68335
commit eccf736c3c

View file

@ -1,9 +1,8 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
* Copyright (c) 2014-2025 Baptiste Daroussin <bapt@FreeBSD.org>
* Copyright (c) 2013 Bryan Drewery <bdrewery@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -332,6 +331,16 @@ parse_mirror_type(struct repository *r, const char *mt)
r->mirror_type = MIRROR_NONE;
}
static void
repo_free(struct repository *r)
{
free(r->name);
free(r->url);
free(r->fingerprints);
free(r->pubkey);
free(r);
}
static bool
parse_signature_type(struct repository *repo, const char *st)
{
@ -344,11 +353,7 @@ parse_signature_type(struct repository *repo, const char *st)
else {
warnx("Signature type %s is not supported for bootstrapping,"
" ignoring repository %s", st, repo->name);
free(repo->url);
free(repo->name);
free(repo->fingerprints);
free(repo->pubkey);
free(repo);
repo_free(repo);
return false;
}
return (true);
@ -392,13 +397,16 @@ parse_repo(const ucl_object_t *o)
} else if (strcasecmp(key, "enabled") == 0) {
if ((cur->type != UCL_BOOLEAN) ||
!ucl_object_toboolean(cur)) {
free(repo->url);
free(repo->name);
free(repo);
repo_free(repo);
return;
}
}
}
/* At least we need an url */
if (repo->url == NULL) {
repo_free(repo);
return;
}
STAILQ_INSERT_TAIL(&repositories, repo, next);
return;
}