libxbps: ABI/API break due to xbps_pkg{,pattern}_name changes.

The funcs xbps_pkg_name() and xbps_pkgpattern_name() were
using malloc(3) to return the result, until now.

They now have been changed to not allocate the result
via malloc, the caller is responsible to provide a buffer
at least of XBPS_NAME_SIZE (64).

If for whatever reason the pkgname can't be guessed,
returns false. This should avoid lots of small allocs
around libxbps.

New functions have the following prototype:

bool xbps_pkg_name(char *dst, size_t len, const char *pkg)
bool xbps_pkgpattern_name(char *dst, size_t len, const char *pkg)

as suggested by @duncaen.
This commit is contained in:
Juan RP 2020-02-08 19:31:29 +01:00
parent 1cda3017c3
commit 6010a24de6
35 changed files with 377 additions and 435 deletions

View File

@ -830,7 +830,7 @@ main(int argc, char **argv)
const char *arch, *config_files, *mutable_files, *version, *changelog; const char *arch, *config_files, *mutable_files, *version, *changelog;
const char *buildopts, *shlib_provides, *shlib_requires, *alternatives; const char *buildopts, *shlib_provides, *shlib_requires, *alternatives;
const char *compression, *tags = NULL, *srcrevs = NULL; const char *compression, *tags = NULL, *srcrevs = NULL;
char *pkgname, *binpkg, *tname, *p, cwd[PATH_MAX-1]; char pkgname[XBPS_NAME_SIZE], *binpkg, *tname, *p, cwd[PATH_MAX-1];
bool quiet = false, preserve = false; bool quiet = false, preserve = false;
int c, pkg_fd; int c, pkg_fd;
mode_t myumask; mode_t myumask;
@ -947,8 +947,7 @@ main(int argc, char **argv)
/* /*
* Sanity check for required options. * Sanity check for required options.
*/ */
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
if (pkgname == NULL)
die("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver); die("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver);
version = xbps_pkg_version(pkgver); version = xbps_pkg_version(pkgver);
if (version == NULL) if (version == NULL)

View File

@ -36,7 +36,7 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
{ {
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
const char *instver, *newver; const char *instver, *newver;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
int rv = 0; int rv = 0;
bool slog = false; bool slog = false;
@ -99,8 +99,9 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
/* empty */ /* empty */
break; break;
case XBPS_STATE_UPDATE: case XBPS_STATE_UPDATE:
pkgname = xbps_pkg_name(xscd->arg); if (!xbps_pkg_name(pkgname, sizeof(pkgname), xscd->arg)) {
assert(pkgname); abort();
}
newver = xbps_pkg_version(xscd->arg); newver = xbps_pkg_version(xscd->arg);
pkgd = xbps_pkgdb_get_pkg(xscd->xhp, pkgname); pkgd = xbps_pkgdb_get_pkg(xscd->xhp, pkgname);
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &instver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &instver);
@ -110,7 +111,6 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
"(rootdir: %s)\n", instver, newver, "(rootdir: %s)\n", instver, newver,
xscd->xhp->rootdir); xscd->xhp->rootdir);
} }
free(pkgname);
break; break;
/* success */ /* success */
case XBPS_STATE_REMOVE_FILE: case XBPS_STATE_REMOVE_FILE:

View File

@ -93,18 +93,18 @@ show_package_list(struct transaction *trans, const char *match, int cols)
if (match && strcmp(tract, "update") == 0) { if (match && strcmp(tract, "update") == 0) {
xbps_dictionary_t ipkgd; xbps_dictionary_t ipkgd;
const char *ipkgver, *iversion, *version; const char *ipkgver, *iversion, *version;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
/* get installed pkgver */ /* get installed pkgver */
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname); ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname);
assert(ipkgd); assert(ipkgd);
xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver); xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver);
version = xbps_pkg_version(pkgver); version = xbps_pkg_version(pkgver);
iversion = xbps_pkg_version(ipkgver); iversion = xbps_pkg_version(ipkgver);
buf = xbps_xasprintf("%s (%s -> %s)", pkgname, iversion, version); buf = xbps_xasprintf("%s (%s -> %s)", pkgname, iversion, version);
free(pkgname);
} }
if ((match && (strcmp(match, tract) == 0)) || (!match && dload)) { if ((match && (strcmp(match, tract) == 0)) || (!match && dload)) {
if (buf) { if (buf) {

View File

@ -82,15 +82,15 @@ find_longest_pkgname(struct transaction *trans)
{ {
xbps_object_t obj; xbps_object_t obj;
const char *pkgver; const char *pkgver;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
unsigned int len = 0, max = 0; unsigned int len = 0, max = 0;
while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) { while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
len = strlen(pkgname); len = strlen(pkgname);
free(pkgname);
if (max == 0 || len > max) if (max == 0 || len > max)
max = len; max = len;
} }
@ -125,7 +125,7 @@ print_trans_colmode(struct transaction *trans, int cols)
while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) { while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) {
xbps_dictionary_t ipkgd; xbps_dictionary_t ipkgd;
const char *pkgver, *ipkgver, *ver, *iver, *tract; const char *pkgver, *ipkgver, *ver, *iver, *tract;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
bool dload = false; bool dload = false;
ver = iver = NULL; ver = iver = NULL;
@ -135,8 +135,9 @@ print_trans_colmode(struct transaction *trans, int cols)
xbps_dictionary_get_uint64(obj, "filename-size", &dlsize); xbps_dictionary_get_uint64(obj, "filename-size", &dlsize);
xbps_dictionary_get_bool(obj, "download", &dload); xbps_dictionary_get_bool(obj, "download", &dload);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
if (trans->xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) { if (trans->xhp->flags & XBPS_FLAG_DOWNLOAD_ONLY) {
tract = "download"; tract = "download";
@ -206,7 +207,6 @@ print_trans_colmode(struct transaction *trans, int cols)
/* print download size */ /* print download size */
printf("%s ", size); printf("%s ", size);
printf("\n"); printf("\n");
free(pkgname);
} }
xbps_object_iterator_reset(trans->iter); xbps_object_iterator_reset(trans->iter);
return true; return true;

View File

@ -43,19 +43,19 @@ pkgdb_cb(struct xbps_handle *xhp UNUSED,
bool *done UNUSED) bool *done UNUSED)
{ {
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
int rv, *errors = (int *)arg; int rv, *errors = (int *)arg;
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (xhp->flags & XBPS_FLAG_VERBOSE) if (xhp->flags & XBPS_FLAG_VERBOSE)
printf("Checking %s ...\n", pkgver); printf("Checking %s ...\n", pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
if ((rv = check_pkg_integrity(xhp, obj, pkgname)) != 0) if ((rv = check_pkg_integrity(xhp, obj, pkgname)) != 0)
*errors += 1; *errors += 1;
free(pkgname);
return 0; return 0;
} }

View File

@ -252,7 +252,8 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
*/ */
for (int i = args; i < argmax; i++) { for (int i = args; i < argmax; i++) {
const char *arch = NULL, *pkg = argv[i]; const char *arch = NULL, *pkg = argv[i];
char *sha256 = NULL, *pkgver = NULL, *pkgname = NULL; char *sha256 = NULL, *pkgver = NULL;
char pkgname[XBPS_NAME_SIZE];
assert(pkg); assert(pkg);
/* /*
@ -272,8 +273,9 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
free(pkgver); free(pkgver);
continue; continue;
} }
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
/* /*
* Check if this package exists already in the index, but first * Check if this package exists already in the index, but first
* checking the version. If current package version is greater * checking the version. If current package version is greater
@ -288,7 +290,6 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
rv = errno; rv = errno;
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(pkgver); free(pkgver);
free(pkgname);
goto out; goto out;
} }
} else if (!force) { } else if (!force) {
@ -320,7 +321,6 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
free(opkgver); free(opkgver);
free(oarch); free(oarch);
free(pkgver); free(pkgver);
free(pkgname);
continue; continue;
} }
free(opkgver); free(opkgver);
@ -334,7 +334,6 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
if ((sha256 = xbps_file_hash(pkg)) == NULL) { if ((sha256 = xbps_file_hash(pkg)) == NULL) {
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(pkgver); free(pkgver);
free(pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
@ -342,7 +341,6 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(sha256); free(sha256);
free(pkgver); free(pkgver);
free(pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
@ -350,14 +348,12 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
if (stat(pkg, &st) == -1) { if (stat(pkg, &st) == -1) {
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(pkgver); free(pkgver);
free(pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (!xbps_dictionary_set_uint64(binpkgd, "filename-size", (uint64_t)st.st_size)) { if (!xbps_dictionary_set_uint64(binpkgd, "filename-size", (uint64_t)st.st_size)) {
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(pkgver); free(pkgver);
free(pkgname);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
@ -371,13 +367,11 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
*/ */
if (!xbps_dictionary_set(idxstage, pkgname, binpkgd)) { if (!xbps_dictionary_set(idxstage, pkgname, binpkgd)) {
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(pkgname);
free(pkgver); free(pkgver);
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
xbps_object_release(binpkgd); xbps_object_release(binpkgd);
free(pkgname);
free(pkgver); free(pkgver);
} }
/* /*

View File

@ -54,7 +54,7 @@ idx_cleaner_cb(struct xbps_handle *xhp,
{ {
struct CleanerCbInfo *info = arg; struct CleanerCbInfo *info = arg;
const char *arch = NULL, *pkgver = NULL, *sha256 = NULL; const char *arch = NULL, *pkgver = NULL, *sha256 = NULL;
char *filen, *pkgname; char *filen, pkgname[XBPS_NAME_SIZE];
xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch); xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
@ -67,11 +67,9 @@ idx_cleaner_cb(struct xbps_handle *xhp,
* File cannot be read, might be permissions, * File cannot be read, might be permissions,
* broken or simply unexistent; either way, remove it. * broken or simply unexistent; either way, remove it.
*/ */
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
if (pkgname == NULL)
goto out; goto out;
xbps_dictionary_remove(dest, pkgname); xbps_dictionary_remove(dest, pkgname);
free(pkgname);
printf("index: removed pkg %s\n", pkgver); printf("index: removed pkg %s\n", pkgver);
} else if (info->hashcheck) { } else if (info->hashcheck) {
/* /*
@ -80,11 +78,9 @@ idx_cleaner_cb(struct xbps_handle *xhp,
xbps_dictionary_get_cstring_nocopy(obj, xbps_dictionary_get_cstring_nocopy(obj,
"filename-sha256", &sha256); "filename-sha256", &sha256);
if (xbps_file_hash_check(filen, sha256) != 0) { if (xbps_file_hash_check(filen, sha256) != 0) {
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
if (pkgname == NULL)
goto out; goto out;
xbps_dictionary_remove(dest, pkgname); xbps_dictionary_remove(dest, pkgname);
free(pkgname);
printf("index: removed pkg %s\n", pkgver); printf("index: removed pkg %s\n", pkgver);
} }
} }

View File

@ -102,7 +102,7 @@ main(int argc, char **argv)
struct xbps_handle xh; struct xbps_handle xh;
struct xferstat xfer; struct xferstat xfer;
const char *version, *rootdir = NULL, *confdir = NULL; const char *version, *rootdir = NULL, *confdir = NULL;
char *pkgname, *filename; char pkgname[XBPS_NAME_SIZE], *filename;
int flags = 0, c, rv = 0; int flags = 0, c, rv = 0;
const struct option longopts[] = { const struct option longopts[] = {
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
@ -197,14 +197,12 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
pkgname = xbps_pkg_name(argv[1]); if (!xbps_pkg_name(pkgname, sizeof(pkgname), argv[1])) {
if (pkgname == NULL) {
fprintf(stderr, fprintf(stderr,
"Invalid string, expected <string>-<version>_<revision>\n"); "Invalid string, expected <string>-<version>_<revision>\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf("%s\n", pkgname); printf("%s\n", pkgname);
free(pkgname);
} else if (strcmp(argv[0], "getpkgrevision") == 0) { } else if (strcmp(argv[0], "getpkgrevision") == 0) {
/* Returns the revision of a pkg string */ /* Returns the revision of a pkg string */
if (argc != 2) if (argc != 2)
@ -220,12 +218,10 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
pkgname = xbps_pkgpattern_name(argv[1]); if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), argv[1]))
if (pkgname == NULL)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
printf("%s\n", pkgname); printf("%s\n", pkgname);
free(pkgname);
} else if (strcmp(argv[0], "getpkgdepversion") == 0) { } else if (strcmp(argv[0], "getpkgdepversion") == 0) {
/* returns the version of a package pattern dependency */ /* returns the version of a package pattern dependency */
if (argc != 2) if (argc != 2)

View File

@ -43,6 +43,7 @@
#include <archive_entry.h> #include <archive_entry.h>
#define XBPS_MAXPATH 512 #define XBPS_MAXPATH 512
#define XBPS_NAME_SIZE 64
/** /**
* @file include/xbps.h * @file include/xbps.h
@ -50,7 +51,7 @@
* *
* This header documents the full API for the XBPS Library. * This header documents the full API for the XBPS Library.
*/ */
#define XBPS_API_VERSION "20200118" #define XBPS_API_VERSION "20200208"
#ifndef XBPS_VERSION #ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET" #define XBPS_VERSION "UNSET"
@ -1977,27 +1978,27 @@ char *xbps_repository_pkg_path(struct xbps_handle *xhp, xbps_dictionary_t pkgd);
* by a @<pkgname@>/@<version@> pair and separated by the <em>minus</em> * by a @<pkgname@>/@<version@> pair and separated by the <em>minus</em>
* sign, i.e <b>foo-2.0</b>. * sign, i.e <b>foo-2.0</b>.
* *
* @param[in] pkg Package string. * @param[out] dst Destination buffer to store result.
* @param[in] len Length of \a dst.
* @param[in] pkg Package version string.
* *
* @return A pointer to a malloc(3)d string, NULL otherwise and * @return true on success, false otherwise.
* errno is set appropiately. The pointer should be free(3)d when it's
* no longer needed.
*/ */
char *xbps_pkg_name(const char *pkg); bool xbps_pkg_name(char *dst, size_t len, const char *pkg);
/** /**
* Gets a the package name of a package pattern string specified by * Gets a the package name of a package pattern string specified by
* the \a pattern argument. * the \a pattern argument.
* *
* @param[out] dst Destination buffer to store result.
* @param[in] len Length of \a dst.
* @param[in] pattern A package pattern. Package patterns are composed * @param[in] pattern A package pattern. Package patterns are composed
* by looking at <b>'><='</b> to split components, i.e <b>foo>=2.0</b>, * by looking at <b>'><='</b> to split components, i.e <b>foo>=2.0</b>,
* <b>blah<1.0</b>, <b>blob==2.0</b>, etc. * <b>blah<1.0</b>, <b>blob==2.0</b>, etc.
* *
* @return A pointer to a malloc(3)ed string with the package name, * @return true on success, false otherwise.
* NULL otherwise and errno is set appropiately. The pointer should be
* free(3)d when it's no longer needed.
*/ */
char *xbps_pkgpattern_name(const char *pattern); bool xbps_pkgpattern_name(char *dst, size_t len, const char *pattern);
/** /**
* Gets the package version in a package string, i.e <b>foo-2.0</b>. * Gets the package version in a package string, i.e <b>foo-2.0</b>.

View File

@ -2,8 +2,8 @@
RANLIB ?= ranlib RANLIB ?= ranlib
LIBXBPS_MAJOR = 4 LIBXBPS_MAJOR = 5
LIBXBPS_MINOR = 1 LIBXBPS_MINOR = 0
LIBXBPS_MICRO = 0 LIBXBPS_MICRO = 0
LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO) LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO)
LDFLAGS += $(LIBXBPS_LDFLAGS) -shared -Wl,-soname,libxbps.so.$(LIBXBPS_MAJOR) LDFLAGS += $(LIBXBPS_LDFLAGS) -shared -Wl,-soname,libxbps.so.$(LIBXBPS_MAJOR)

View File

@ -331,7 +331,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
xbps_array_t allkeys; xbps_array_t allkeys;
xbps_dictionary_t alternatives, pkg_alternatives; xbps_dictionary_t alternatives, pkg_alternatives;
const char *pkgver; const char *pkgver;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
bool update = false; bool update = false;
int rv = 0; int rv = 0;
@ -346,7 +346,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
return 0; return 0;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
if ((pkgname = xbps_pkg_name(pkgver)) == NULL) if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
return EINVAL; return EINVAL;
xbps_dictionary_get_bool(pkgd, "alternatives-update", &update); xbps_dictionary_get_bool(pkgd, "alternatives-update", &update);
@ -396,7 +396,6 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
break; break;
} }
xbps_object_release(allkeys); xbps_object_release(allkeys);
free(pkgname);
return rv; return rv;
} }
@ -410,7 +409,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
*/ */
static void static void
prune_altgroup(struct xbps_handle *xhp, xbps_dictionary_t repod, prune_altgroup(struct xbps_handle *xhp, xbps_dictionary_t repod,
char *pkgname, const char *pkgver, const char *keyname) const char *pkgname, const char *pkgver, const char *keyname)
{ {
const char *newpkg = NULL, *curpkg = NULL; const char *newpkg = NULL, *curpkg = NULL;
xbps_array_t array; xbps_array_t array;
@ -533,7 +532,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
xbps_array_t allkeys; xbps_array_t allkeys;
xbps_dictionary_t alternatives, pkg_alternatives; xbps_dictionary_t alternatives, pkg_alternatives;
const char *pkgver; const char *pkgver;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
int rv = 0; int rv = 0;
assert(xhp); assert(xhp);
@ -551,8 +550,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
assert(alternatives); assert(alternatives);
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
if (pkgname == NULL)
return EINVAL; return EINVAL;
/* /*
@ -612,7 +610,6 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
break; break;
} }
xbps_object_release(allkeys); xbps_object_release(allkeys);
free(pkgname);
return rv; return rv;
} }

View File

@ -90,28 +90,26 @@ xbps_configure_pkg(struct xbps_handle *xhp,
bool update) bool update)
{ {
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
char *pkgname; const char *p;
char pkgname[XBPS_NAME_SIZE];
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
mode_t myumask; mode_t myumask;
assert(pkgver != NULL); assert(pkgver != NULL);
if ((pkgname = xbps_pkg_name(pkgver)) == NULL) { if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
xbps_dbg_printf(xhp, "[configure] cannot guess " p = pkgver;
"pkgname for %s\n", pkgver); } else {
/* assume pkgver == pkgname */ p = pkgname;
pkgname = strdup(pkgver);
assert(pkgname);
} }
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
pkgd = xbps_pkgdb_get_pkg(xhp, p);
if (pkgd == NULL) { if (pkgd == NULL) {
xbps_dbg_printf(xhp, "[configure] cannot find %s (%s) " xbps_dbg_printf(xhp, "[configure] cannot find %s (%s) "
"in pkgdb\n", pkgname, pkgver); "in pkgdb\n", p, pkgver);
free(pkgname);
return ENOENT; return ENOENT;
} }
free(pkgname);
rv = xbps_pkg_state_dictionary(pkgd, &state); rv = xbps_pkg_state_dictionary(pkgd, &state);
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv); xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv);

View File

@ -145,7 +145,7 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
xbps_string_t str; xbps_string_t str;
struct item *item, *xitem; struct item *item, *xitem;
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgn; char pkgn[XBPS_NAME_SIZE];
assert(xhp); assert(xhp);
assert(pkgd); assert(pkgd);
@ -154,8 +154,9 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
provides = xbps_dictionary_get(pkgd, "provides"); provides = xbps_dictionary_get(pkgd, "provides");
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgn = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgn, sizeof(pkgn), pkgver)) {
assert(pkgn); abort();
}
item = lookupItem(pkgn); item = lookupItem(pkgn);
if (item) { if (item) {
add_deps_recursive(item, depth == 0); add_deps_recursive(item, depth == 0);
@ -165,12 +166,11 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
item = addItem(rdeps, pkgn); item = addItem(rdeps, pkgn);
item->pkgver = pkgver; item->pkgver = pkgver;
assert(item); assert(item);
free(pkgn);
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) { for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
xbps_dictionary_t curpkgd; xbps_dictionary_t curpkgd;
const char *curdep = NULL; const char *curdep = NULL;
char *curdepname; char curdepname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curdep); xbps_array_get_cstring_nocopy(rdeps, i, &curdep);
if (rpool) { if (rpool) {
@ -189,15 +189,14 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
errno = ENODEV; errno = ENODEV;
return NULL; return NULL;
} }
if ((curdepname = xbps_pkgpattern_name(curdep)) == NULL) if ((!xbps_pkgpattern_name(curdepname, XBPS_NAME_SIZE, curdep)) &&
curdepname = xbps_pkg_name(curdep); (!xbps_pkg_name(curdepname, XBPS_NAME_SIZE, curdep))) {
abort();
assert(curdepname); }
if (provides && xbps_match_pkgname_in_array(provides, curdepname)) { if (provides && xbps_match_pkgname_in_array(provides, curdepname)) {
xbps_dbg_printf(xhp, "%s: ignoring dependency %s " xbps_dbg_printf(xhp, "%s: ignoring dependency %s "
"already in provides\n", pkgver, curdep); "already in provides\n", pkgver, curdep);
free(curdepname);
continue; continue;
} }
xitem = lookupItem(curdepname); xitem = lookupItem(curdepname);
@ -214,7 +213,6 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
} }
assert(xitem); assert(xitem);
addDepn(item, xitem); addDepn(item, xitem);
free(curdepname);
} }
/* all deps were processed, add item to head */ /* all deps were processed, add item to head */
if (depth > 0 && !xbps_match_string_in_array(result, item->pkgver)) { if (depth > 0 && !xbps_match_string_in_array(result, item->pkgver)) {

View File

@ -36,12 +36,12 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
{ {
xbps_array_t replaces; xbps_array_t replaces;
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
char outstr[64]; char outstr[64], pkgname[XBPS_NAME_SIZE];
time_t t; time_t t;
struct tm tm; struct tm tm;
struct tm *tmp; struct tm *tmp;
const char *pkgver; const char *pkgver;
char *pkgname = NULL, *buf, *sha256; char *buf, *sha256;
int rv = 0; int rv = 0;
bool autoinst = false; bool autoinst = false;
@ -51,8 +51,11 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
pkgd = xbps_dictionary_copy_mutable(pkgrd); pkgd = xbps_dictionary_copy_mutable(pkgrd);
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); xbps_dbg_printf(xhp, "%s: invalid pkgname %s\n", __func__, pkgver);
rv = EINVAL;
goto out;
}
if (xhp->flags & XBPS_FLAG_INSTALL_AUTO) if (xhp->flags & XBPS_FLAG_INSTALL_AUTO)
autoinst = true; autoinst = true;
@ -130,8 +133,6 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
} }
out: out:
xbps_object_release(pkgd); xbps_object_release(pkgd);
if (pkgname)
free(pkgname);
return rv; return rv;
} }

View File

@ -111,7 +111,7 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
{ {
xbps_dictionary_t pkgd = NULL, obsd = NULL; xbps_dictionary_t pkgd = NULL, obsd = NULL;
xbps_array_t obsoletes = NULL; xbps_array_t obsoletes = NULL;
char *pkgname, metafile[PATH_MAX]; char pkgname[XBPS_NAME_SIZE], metafile[PATH_MAX];
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
uid_t euid; uid_t euid;
@ -119,8 +119,9 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
assert(xhp); assert(xhp);
assert(pkgver); assert(pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
euid = geteuid(); euid = geteuid();
@ -181,7 +182,6 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
* overwritten later in unpack phase. * overwritten later in unpack phase.
*/ */
if (update) { if (update) {
free(pkgname);
return 0; return 0;
} }
@ -259,8 +259,6 @@ purge:
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL); xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL);
xbps_dictionary_remove(xhp->pkgdb, pkgname); xbps_dictionary_remove(xhp->pkgdb, pkgname);
out: out:
if (pkgname != NULL)
free(pkgname);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver,
"%s: failed to remove package: %s", pkgver, strerror(rv)); "%s: failed to remove package: %s", pkgver, strerror(rv));

View File

@ -49,7 +49,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
"/bin/bash", "/bin/bash",
NULL NULL
}; };
char *pkgname, *fpath; char pkgname[XBPS_NAME_SIZE], *fpath;
int fd, rv; int fd, rv;
assert(blob); assert(blob);
@ -103,8 +103,9 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
close(fd); close(fd);
/* exec script */ /* exec script */
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
version = xbps_pkg_version(pkgver); version = xbps_pkg_version(pkgver);
assert(version); assert(version);
@ -129,7 +130,6 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
} else { } else {
rv = -1; rv = -1;
} }
free(pkgname);
out: out:
remove(fpath); remove(fpath);

View File

@ -138,7 +138,7 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
pkg_state_t state) pkg_state_t state)
{ {
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
int rv = 0; int rv = 0;
assert(pkgver != NULL); assert(pkgver != NULL);
@ -158,26 +158,24 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
xbps_object_release(pkgd); xbps_object_release(pkgd);
return rv; return rv;
} }
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) { if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
xbps_object_release(pkgd); xbps_object_release(pkgd);
free(pkgname);
return EINVAL; return EINVAL;
} }
free(pkgname);
xbps_object_release(pkgd); xbps_object_release(pkgd);
} else { } else {
if ((rv = set_new_state(pkgd, state)) != 0) if ((rv = set_new_state(pkgd, state)) != 0)
return rv; return rv;
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) { if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
free(pkgname);
return EINVAL; return EINVAL;
} }
free(pkgname);
} }
return rv; return rv;

View File

@ -84,7 +84,7 @@ unpack_archive(struct xbps_handle *xhp,
size_t instbufsiz = 0, rembufsiz = 0; size_t instbufsiz = 0, rembufsiz = 0;
ssize_t entry_size; ssize_t entry_size;
const char *entry_pname, *transact, *binpkg_pkgver; const char *entry_pname, *transact, *binpkg_pkgver;
char *pkgname, *buf = NULL; char pkgname[XBPS_NAME_SIZE], *buf = NULL;
int ar_rv, rv, error, entry_type, flags; int ar_rv, rv, error, entry_type, flags;
bool preserve, update, file_exists, keep_conf_file; bool preserve, update, file_exists, keep_conf_file;
bool skip_extract, force, xucd_stats; bool skip_extract, force, xucd_stats;
@ -102,8 +102,9 @@ unpack_archive(struct xbps_handle *xhp,
euid = geteuid(); euid = geteuid();
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
if (xhp->flags & XBPS_FLAG_FORCE_UNPACK) if (xhp->flags & XBPS_FLAG_FORCE_UNPACK)
force = true; force = true;
@ -550,8 +551,6 @@ out:
xbps_object_release(binpkg_propsd); xbps_object_release(binpkg_propsd);
if (xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY) if (xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY)
xbps_object_release(binpkg_filesd); xbps_object_release(binpkg_filesd);
if (pkgname != NULL)
free(pkgname);
if (instbuf != NULL) if (instbuf != NULL)
free(instbuf); free(instbuf);
if (rembuf != NULL) if (rembuf != NULL)

View File

@ -160,7 +160,7 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp)
xbps_array_t provides; xbps_array_t provides;
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgname = NULL; char pkgname[XBPS_NAME_SIZE];
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj); pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
provides = xbps_dictionary_get(pkgd, "provides"); provides = xbps_dictionary_get(pkgd, "provides");
@ -168,9 +168,10 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp)
continue; continue;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); rv = EINVAL;
break;
}
for (unsigned int i = 0; i < xbps_array_count(provides); i++) { for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
const char *vpkg = NULL; const char *vpkg = NULL;
@ -179,12 +180,14 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp)
xbps_dbg_printf(xhp, "%s: set_cstring vpkg " xbps_dbg_printf(xhp, "%s: set_cstring vpkg "
"%s pkgname %s\n", __func__, vpkg, pkgname); "%s pkgname %s\n", __func__, vpkg, pkgname);
rv = EINVAL; rv = EINVAL;
break;
} else { } else {
xbps_dbg_printf(xhp, "[pkgdb] added vpkg %s for %s\n", xbps_dbg_printf(xhp, "[pkgdb] added vpkg %s for %s\n",
vpkg, pkgname); vpkg, pkgname);
} }
} }
free(pkgname); if (rv)
break;
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
return rv; return rv;
@ -369,28 +372,31 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
for (unsigned int i = 0; i < xbps_array_count(rundeps); i++) { for (unsigned int i = 0; i < xbps_array_count(rundeps); i++) {
xbps_array_t pkg; xbps_array_t pkg;
const char *pkgdep = NULL, *vpkgname = NULL; const char *pkgdep = NULL, *vpkgname = NULL;
char *curpkgname; char *v, curpkgname[XBPS_NAME_SIZE];
bool alloc = false; bool alloc = false;
xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep); xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep);
curpkgname = xbps_pkgpattern_name(pkgdep); if ((!xbps_pkgpattern_name(curpkgname, sizeof(curpkgname), pkgdep)) &&
if (curpkgname == NULL) (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))) {
curpkgname = xbps_pkg_name(pkgdep); abort();
assert(curpkgname); }
vpkgname = vpkg_user_conf(xhp, curpkgname, false); vpkgname = vpkg_user_conf(xhp, curpkgname, false);
if (vpkgname == NULL) if (vpkgname == NULL) {
vpkgname = curpkgname; v = strdup(curpkgname);
} else {
v = strdup(vpkgname);
}
pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, vpkgname); pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, v);
if (pkg == NULL) { if (pkg == NULL) {
alloc = true; alloc = true;
pkg = xbps_array_create(); pkg = xbps_array_create();
} }
if (!xbps_match_string_in_array(pkg, pkgver)) { if (!xbps_match_string_in_array(pkg, pkgver)) {
xbps_array_add_cstring_nocopy(pkg, pkgver); xbps_array_add_cstring_nocopy(pkg, pkgver);
xbps_dictionary_set(xhp->pkgdb_revdeps, vpkgname, pkg); xbps_dictionary_set(xhp->pkgdb_revdeps, v, pkg);
} }
free(curpkgname); free(v);
if (alloc) if (alloc)
xbps_object_release(pkg); xbps_object_release(pkg);
} }
@ -401,23 +407,19 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
xbps_array_t xbps_array_t
xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg) xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
{ {
xbps_array_t res;
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkg)) == NULL) if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkg)) == NULL)
return NULL; return NULL;
generate_full_revdeps_tree(xhp); generate_full_revdeps_tree(xhp);
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
if ((pkgname = xbps_pkg_name(pkgver)) == NULL) if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
return NULL; return NULL;
res = xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname); return xbps_dictionary_get(xhp->pkgdb_revdeps, pkgname);
free(pkgname);
return res;
} }
xbps_array_t xbps_array_t
@ -431,7 +433,7 @@ xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg)
{ {
xbps_dictionary_t pkgd, pkgfilesd; xbps_dictionary_t pkgd, pkgfilesd;
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgname, *plist; char pkgname[XBPS_NAME_SIZE], *plist;
if (pkg == NULL) if (pkg == NULL)
return NULL; return NULL;
@ -441,11 +443,10 @@ xbps_pkgdb_get_pkg_files(struct xbps_handle *xhp, const char *pkg)
return NULL; return NULL;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
assert(pkgname); return NULL;
plist = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname); plist = xbps_xasprintf("%s/.%s-files.plist", xhp->metadir, pkgname);
free(pkgname);
pkgfilesd = xbps_plist_dictionary_from_file(xhp, plist); pkgfilesd = xbps_plist_dictionary_from_file(xhp, plist);
free(plist); free(plist);

View File

@ -225,7 +225,7 @@ array_replace_dict(xbps_array_t array,
{ {
xbps_object_t obj; xbps_object_t obj;
const char *curpkgver; const char *curpkgver;
char *curpkgname; char curpkgname[XBPS_NAME_SIZE];
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY); assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY); assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
@ -249,17 +249,15 @@ array_replace_dict(xbps_array_t array,
/* pkgname match */ /* pkgname match */
xbps_dictionary_get_cstring_nocopy(obj, xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &curpkgver); "pkgver", &curpkgver);
curpkgname = xbps_pkg_name(curpkgver); if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
assert(curpkgname); abort();
}
if (strcmp(curpkgname, str) == 0) { if (strcmp(curpkgname, str) == 0) {
if (!xbps_array_set(array, i, dict)) { if (!xbps_array_set(array, i, dict)) {
free(curpkgname);
return EINVAL; return EINVAL;
} }
free(curpkgname);
return 0; return 0;
} }
free(curpkgname);
} }
} }
/* no match */ /* no match */

View File

@ -47,7 +47,7 @@ get_pkg_in_array(xbps_array_t array, const char *str, const char *trans, bool vi
while ((obj = xbps_object_iterator_next(iter))) { while ((obj = xbps_object_iterator_next(iter))) {
const char *pkgver; const char *pkgver;
char *dpkgn; char dpkgn[XBPS_NAME_SIZE];
if (virtual) { if (virtual) {
/* /*
@ -80,14 +80,13 @@ get_pkg_in_array(xbps_array_t array, const char *str, const char *trans, bool vi
if (!xbps_dictionary_get_cstring_nocopy(obj, if (!xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) "pkgver", &pkgver))
continue; continue;
dpkgn = xbps_pkg_name(pkgver); if (!xbps_pkg_name(dpkgn, sizeof(dpkgn), pkgver)) {
assert(dpkgn); abort();
}
if (strcmp(dpkgn, str) == 0) { if (strcmp(dpkgn, str) == 0) {
free(dpkgn);
found = true; found = true;
break; break;
} }
free(dpkgn);
} }
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
@ -139,10 +138,10 @@ match_pkg_by_pkgver(xbps_dictionary_t repod, const char *p)
{ {
xbps_dictionary_t d = NULL; xbps_dictionary_t d = NULL;
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
/* exact match by pkgver */ /* exact match by pkgver */
if ((pkgname = xbps_pkg_name(p)) == NULL) if (!xbps_pkg_name(pkgname, sizeof(pkgname), p))
return NULL; return NULL;
d = xbps_dictionary_get(repod, pkgname); d = xbps_dictionary_get(repod, pkgname);
@ -154,7 +153,6 @@ match_pkg_by_pkgver(xbps_dictionary_t repod, const char *p)
} }
} }
free(pkgname);
return d; return d;
} }
@ -163,12 +161,11 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p)
{ {
xbps_dictionary_t d = NULL; xbps_dictionary_t d = NULL;
const char *pkgver = NULL; const char *pkgver = NULL;
char *pkgname = NULL; char pkgname[XBPS_NAME_SIZE];
/* match by pkgpattern in pkgver */ /* match by pkgpattern in pkgver */
if ((pkgname = xbps_pkgpattern_name(p)) == NULL) { if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), p)) {
if ((pkgname = xbps_pkg_name(p))) { if (xbps_pkg_name(pkgname, sizeof(pkgname), p)) {
free(pkgname);
return match_pkg_by_pkgver(repod, p); return match_pkg_by_pkgver(repod, p);
} }
return NULL; return NULL;
@ -184,7 +181,6 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p)
} }
} }
free(pkgname);
return d; return d;
} }
@ -213,7 +209,8 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
while ((obj = xbps_object_iterator_next(iter))) { while ((obj = xbps_object_iterator_next(iter))) {
xbps_string_t rpkg; xbps_string_t rpkg;
char *dpkgname, *vpkgname; char buf[XBPS_NAME_SIZE];
char *vpkgname;
const char *vpkg_conf; const char *vpkg_conf;
vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj); vpkg_conf = xbps_dictionary_keysym_cstring_nocopy(obj);
@ -221,12 +218,14 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
pkg = xbps_string_cstring_nocopy(rpkg); pkg = xbps_string_cstring_nocopy(rpkg);
if (xbps_pkg_version(vpkg_conf)) { if (xbps_pkg_version(vpkg_conf)) {
vpkgname = xbps_pkg_name(vpkg_conf); if (!xbps_pkg_name(buf, XBPS_NAME_SIZE, vpkg_conf)) {
assert(vpkgname); abort();
}
vpkgname = strdup(buf);
} else { } else {
vpkgname = strdup(vpkg_conf); vpkgname = strdup(vpkg_conf);
assert(vpkgname);
} }
assert(vpkgname);
if (xbps_pkgpattern_version(vpkg)) { if (xbps_pkgpattern_version(vpkg)) {
char *vpkgver; char *vpkgver;
@ -246,14 +245,13 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
free(vpkgver); free(vpkgver);
} }
} else if (xbps_pkg_version(vpkg)) { } else if (xbps_pkg_version(vpkg)) {
dpkgname = xbps_pkg_name(vpkg); if (!xbps_pkg_name(buf, XBPS_NAME_SIZE, vpkg)) {
assert(dpkgname); abort();
if (strcmp(dpkgname, vpkgname)) { }
free(dpkgname); if (strcmp(buf, vpkgname)) {
free(vpkgname); free(vpkgname);
continue; continue;
} }
free(dpkgname);
} else { } else {
if (strcmp(vpkg, vpkgname)) { if (strcmp(vpkg, vpkgname)) {
free(vpkgname); free(vpkgname);

View File

@ -103,7 +103,7 @@ match_string_in_array(xbps_array_t array, const char *str, int mode)
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
xbps_object_t obj; xbps_object_t obj;
const char *pkgdep; const char *pkgdep;
char *curpkgname; char pkgname[XBPS_NAME_SIZE];
bool found = false; bool found = false;
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY); assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
@ -122,27 +122,21 @@ match_string_in_array(xbps_array_t array, const char *str, int mode)
} else if (mode == 1) { } else if (mode == 1) {
/* match by pkgname against pkgver */ /* match by pkgname against pkgver */
pkgdep = xbps_string_cstring_nocopy(obj); pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(pkgdep); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgdep))
if (curpkgname == NULL)
break; break;
if (strcmp(curpkgname, str) == 0) { if (strcmp(pkgname, str) == 0) {
free(curpkgname);
found = true; found = true;
break; break;
} }
free(curpkgname);
} else if (mode == 2) { } else if (mode == 2) {
/* match by pkgver against pkgname */ /* match by pkgver against pkgname */
pkgdep = xbps_string_cstring_nocopy(obj); pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(str); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, str))
if (curpkgname == NULL)
break; break;
if (strcmp(curpkgname, pkgdep) == 0) { if (strcmp(pkgname, pkgdep) == 0) {
free(curpkgname);
found = true; found = true;
break; break;
} }
free(curpkgname);
} else if (mode == 3) { } else if (mode == 3) {
/* match pkgpattern against pkgdep */ /* match pkgpattern against pkgdep */
pkgdep = xbps_string_cstring_nocopy(obj); pkgdep = xbps_string_cstring_nocopy(obj);

View File

@ -37,7 +37,7 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
xbps_object_t obj; xbps_object_t obj;
const char *curname, *pkgdep; const char *curname, *pkgdep;
char *curpkgname; char curpkgname[XBPS_NAME_SIZE];
unsigned int idx = 0; unsigned int idx = 0;
bool found = false; bool found = false;
@ -57,15 +57,13 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
} else if (mode == 1) { } else if (mode == 1) {
/* match by pkgname, obj is a string */ /* match by pkgname, obj is a string */
pkgdep = xbps_string_cstring_nocopy(obj); pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(pkgdep); if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))
if (curpkgname == NULL)
break; break;
if (strcmp(curpkgname, str) == 0) { if (strcmp(curpkgname, str) == 0) {
free(curpkgname);
found = true; found = true;
break; break;
} }
free(curpkgname);
} else if (mode == 2) { } else if (mode == 2) {
/* match by pkgname, obj is a dictionary */ /* match by pkgname, obj is a dictionary */
xbps_dictionary_get_cstring_nocopy(obj, xbps_dictionary_get_cstring_nocopy(obj,

View File

@ -556,17 +556,16 @@ xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg)
*/ */
if ((vdeps = xbps_dictionary_get(pkgd, "provides"))) { if ((vdeps = xbps_dictionary_get(pkgd, "provides"))) {
for (unsigned int i = 0; i < xbps_array_count(vdeps); i++) { for (unsigned int i = 0; i < xbps_array_count(vdeps); i++) {
char *vpkgn; char vpkgn[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(vdeps, i, &vpkg); xbps_array_get_cstring_nocopy(vdeps, i, &vpkg);
vpkgn = xbps_pkg_name(vpkg); if (!xbps_pkg_name(vpkgn, XBPS_NAME_SIZE, vpkg)) {
assert(vpkgn); abort();
}
if (strcmp(vpkgn, pkg) == 0) { if (strcmp(vpkgn, pkg) == 0) {
free(vpkgn);
match = true; match = true;
break; break;
} }
free(vpkgn);
vpkg = NULL; vpkg = NULL;
} }
if (match) if (match)

View File

@ -51,7 +51,8 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
while ((obj = xbps_object_iterator_next(iter)) != NULL) { while ((obj = xbps_object_iterator_next(iter)) != NULL) {
const char *curdep, *curver, *pkgver; const char *curdep, *curver, *pkgver;
char *curpkgnamedep = NULL, *pkgnamedep = NULL; char curpkgnamedep[XBPS_NAME_SIZE];
char pkgnamedep[XBPS_NAME_SIZE];
assert(xbps_object_type(obj) == XBPS_TYPE_STRING); assert(xbps_object_type(obj) == XBPS_TYPE_STRING);
curdep = xbps_string_cstring_nocopy(obj); curdep = xbps_string_cstring_nocopy(obj);
@ -59,19 +60,15 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
pkgver = xbps_pkgpattern_version(reqpkg); pkgver = xbps_pkgpattern_version(reqpkg);
if (curver == NULL || pkgver == NULL) if (curver == NULL || pkgver == NULL)
goto out; goto out;
curpkgnamedep = xbps_pkgpattern_name(curdep); if (!xbps_pkgpattern_name(curpkgnamedep, XBPS_NAME_SIZE, curdep)) {
if (curpkgnamedep == NULL)
goto out; goto out;
pkgnamedep = xbps_pkgpattern_name(reqpkg); }
if (pkgnamedep == NULL) { if (!xbps_pkgpattern_name(pkgnamedep, XBPS_NAME_SIZE, reqpkg)) {
free(curpkgnamedep);
goto out; goto out;
} }
if (strcmp(pkgnamedep, curpkgnamedep) == 0) { if (strcmp(pkgnamedep, curpkgnamedep) == 0) {
pkgfound = true; pkgfound = true;
if (strcmp(curver, pkgver) == 0) { if (strcmp(curver, pkgver) == 0) {
free(curpkgnamedep);
free(pkgnamedep);
rv = EEXIST; rv = EEXIST;
goto out; goto out;
} }
@ -82,15 +79,11 @@ add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
xbps_dbg_printf(xhp, "Missing pkgdep name matched, curver: %s newver: %s\n", curver, pkgver); xbps_dbg_printf(xhp, "Missing pkgdep name matched, curver: %s newver: %s\n", curver, pkgver);
if (xbps_cmpver(curver, pkgver) <= 0) { if (xbps_cmpver(curver, pkgver) <= 0) {
add_pkgdep = false; add_pkgdep = false;
free(curpkgnamedep);
free(pkgnamedep);
rv = EEXIST; rv = EEXIST;
goto out; goto out;
} }
update_pkgdep = true; update_pkgdep = true;
} }
free(curpkgnamedep);
free(pkgnamedep);
if (pkgfound) if (pkgfound)
break; break;
@ -123,13 +116,8 @@ find_repo_deps(struct xbps_handle *xhp,
const char *curpkg, /* current pkgver */ const char *curpkg, /* current pkgver */
unsigned short *depth) /* max recursion depth */ unsigned short *depth) /* max recursion depth */
{ {
xbps_dictionary_t curpkgd = NULL;
xbps_object_t obj; xbps_object_t obj;
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
xbps_array_t curpkgrdeps = NULL, curpkgprovides = NULL;
pkg_state_t state;
const char *reqpkg, *pkgver_q, *reason = NULL;
char *pkgname, *reqpkgname;
int rv = 0; int rv = 0;
if (*depth >= MAX_DEPTH) if (*depth >= MAX_DEPTH)
@ -143,7 +131,13 @@ find_repo_deps(struct xbps_handle *xhp,
assert(iter); assert(iter);
while ((obj = xbps_object_iterator_next(iter))) { while ((obj = xbps_object_iterator_next(iter))) {
xbps_array_t curpkgrdeps = NULL, curpkgprovides = NULL;
xbps_dictionary_t curpkgd = NULL;
pkg_state_t state;
const char *reqpkg, *pkgver_q, *reason = NULL;
char pkgname[XBPS_NAME_SIZE], reqpkgname[XBPS_NAME_SIZE];
bool error = false, foundvpkg = false; bool error = false, foundvpkg = false;
reqpkg = xbps_string_cstring_nocopy(obj); reqpkg = xbps_string_cstring_nocopy(obj);
if (xhp->flags & XBPS_FLAG_DEBUG) { if (xhp->flags & XBPS_FLAG_DEBUG) {
@ -153,8 +147,8 @@ find_repo_deps(struct xbps_handle *xhp,
} }
xbps_dbg_printf_append(xhp, "%s: requires dependency '%s': ", curpkg ? curpkg : " ", reqpkg); xbps_dbg_printf_append(xhp, "%s: requires dependency '%s': ", curpkg ? curpkg : " ", reqpkg);
} }
if (((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) && if ((!xbps_pkgpattern_name(pkgname, sizeof(pkgname), reqpkg)) &&
((pkgname = xbps_pkg_name(reqpkg)) == NULL)) { (!xbps_pkg_name(pkgname, sizeof(pkgname), reqpkg))) {
xbps_dbg_printf(xhp, "%s: can't guess pkgname for dependency: %s\n", curpkg, reqpkg); xbps_dbg_printf(xhp, "%s: can't guess pkgname for dependency: %s\n", curpkg, reqpkg);
xbps_set_cb_state(xhp, XBPS_STATE_INVALID_DEP, ENXIO, NULL, xbps_set_cb_state(xhp, XBPS_STATE_INVALID_DEP, ENXIO, NULL,
"%s: can't guess pkgname for dependency '%s'", curpkg, reqpkg); "%s: can't guess pkgname for dependency '%s'", curpkg, reqpkg);
@ -166,7 +160,6 @@ find_repo_deps(struct xbps_handle *xhp,
*/ */
if (xbps_pkg_is_ignored(xhp, pkgname)) { if (xbps_pkg_is_ignored(xhp, pkgname)) {
xbps_dbg_printf_append(xhp, "%s ignored.\n", pkgname); xbps_dbg_printf_append(xhp, "%s ignored.\n", pkgname);
free(pkgname);
continue; continue;
} }
/* /*
@ -175,7 +168,6 @@ find_repo_deps(struct xbps_handle *xhp,
*/ */
if (pkg_provides && xbps_match_virtual_pkg_in_array(pkg_provides, reqpkg)) { if (pkg_provides && xbps_match_virtual_pkg_in_array(pkg_provides, reqpkg)) {
xbps_dbg_printf_append(xhp, "%s is a vpkg provided by %s, ignored.\n", pkgname, curpkg); xbps_dbg_printf_append(xhp, "%s is a vpkg provided by %s, ignored.\n", pkgname, curpkg);
free(pkgname);
continue; continue;
} }
/* /*
@ -186,7 +178,6 @@ find_repo_deps(struct xbps_handle *xhp,
(curpkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, reqpkg, NULL))) { (curpkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, reqpkg, NULL))) {
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q); xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
xbps_dbg_printf_append(xhp, " (%s queued)\n", pkgver_q); xbps_dbg_printf_append(xhp, " (%s queued)\n", pkgver_q);
free(pkgname);
continue; continue;
} }
/* /*
@ -208,15 +199,14 @@ find_repo_deps(struct xbps_handle *xhp,
curpkgd = NULL; curpkgd = NULL;
} }
if (curpkgd == NULL) { if (curpkgd == NULL) {
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
/* error */ /* error */
rv = errno; rv = errno;
xbps_dbg_printf(xhp, "failed to find installed pkg for `%s': %s\n", reqpkg, strerror(rv)); xbps_dbg_printf(xhp, "failed to find installed pkg for `%s': %s\n", reqpkg, strerror(rv));
free(pkgname);
break; break;
} }
free(pkgname);
/* Required dependency not installed */ /* Required dependency not installed */
xbps_dbg_printf_append(xhp, "not installed.\n"); xbps_dbg_printf_append(xhp, "not installed.\n");
reason = "install"; reason = "install";
@ -230,7 +220,6 @@ find_repo_deps(struct xbps_handle *xhp,
/* Check its state */ /* Check its state */
if ((rv = xbps_pkg_state_dictionary(curpkgd, &state)) != 0) { if ((rv = xbps_pkg_state_dictionary(curpkgd, &state)) != 0) {
free(pkgname);
break; break;
} }
@ -240,17 +229,18 @@ find_repo_deps(struct xbps_handle *xhp,
* by an installed package. * by an installed package.
*/ */
xbps_dbg_printf_append(xhp, "[virtual] satisfied by `%s'.\n", pkgver_q); xbps_dbg_printf_append(xhp, "[virtual] satisfied by `%s'.\n", pkgver_q);
free(pkgname);
continue; continue;
} }
rv = xbps_pkgpattern_match(pkgver_q, reqpkg); rv = xbps_pkgpattern_match(pkgver_q, reqpkg);
if (rv == 0) { if (rv == 0) {
char *curpkgname; char curpkgname[XBPS_NAME_SIZE];
/* /*
* The version requirement is not satisfied. * The version requirement is not satisfied.
*/ */
curpkgname = xbps_pkg_name(pkgver_q); if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver_q)) {
assert(curpkgname); abort();
}
if (strcmp(pkgname, curpkgname)) { if (strcmp(pkgname, curpkgname)) {
xbps_dbg_printf_append(xhp, "not installed `%s (vpkg)'", pkgver_q); xbps_dbg_printf_append(xhp, "not installed `%s (vpkg)'", pkgver_q);
if (xbps_dictionary_get(curpkgd, "hold")) { if (xbps_dictionary_get(curpkgd, "hold")) {
@ -268,13 +258,10 @@ find_repo_deps(struct xbps_handle *xhp,
reason = "update"; reason = "update";
} }
} }
free(curpkgname);
free(pkgname);
} else if (rv == 1) { } else if (rv == 1) {
/* /*
* The version requirement is satisfied. * The version requirement is satisfied.
*/ */
free(pkgname);
rv = 0; rv = 0;
if (state == XBPS_PKG_STATE_UNPACKED) { if (state == XBPS_PKG_STATE_UNPACKED) {
/* /*
@ -294,7 +281,6 @@ find_repo_deps(struct xbps_handle *xhp,
} else { } else {
/* error matching pkgpattern */ /* error matching pkgpattern */
xbps_dbg_printf(xhp, "failed to match pattern %s with %s\n", reqpkg, pkgver_q); xbps_dbg_printf(xhp, "failed to match pattern %s with %s\n", reqpkg, pkgver_q);
free(pkgname);
break; break;
} }
} }
@ -328,23 +314,25 @@ find_repo_deps(struct xbps_handle *xhp,
continue; continue;
} }
} }
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q); xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
reqpkgname = xbps_pkg_name(pkgver_q); if (!xbps_pkg_name(reqpkgname, sizeof(reqpkgname), pkgver_q)) {
assert(reqpkgname); rv = EINVAL;
break;
}
/* /*
* Check dependency validity. * Check dependency validity.
*/ */
pkgname = xbps_pkg_name(curpkg); if (!xbps_pkg_name(pkgname, sizeof(pkgname), curpkg)) {
assert(pkgname); rv = EINVAL;
break;
}
if (strcmp(pkgname, reqpkgname) == 0) { if (strcmp(pkgname, reqpkgname) == 0) {
xbps_dbg_printf_append(xhp, "[ignoring wrong dependency %s (depends on itself)]\n", reqpkg); xbps_dbg_printf_append(xhp, "[ignoring wrong dependency %s (depends on itself)]\n", reqpkg);
xbps_remove_string_from_array(pkg_rdeps_array, reqpkg); xbps_remove_string_from_array(pkg_rdeps_array, reqpkg);
free(pkgname);
free(reqpkgname);
continue; continue;
} }
free(pkgname);
free(reqpkgname);
/* /*
* Installed package must be updated, check if dependency is * Installed package must be updated, check if dependency is
* satisfied. * satisfied.
@ -354,8 +342,9 @@ find_repo_deps(struct xbps_handle *xhp,
case 0: /* nomatch */ case 0: /* nomatch */
break; break;
case 1: /* match */ case 1: /* match */
pkgname = xbps_pkg_name(pkgver_q); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver_q)) {
assert(pkgname); abort();
}
/* /*
* If there's an update in transaction, * If there's an update in transaction,
* it's assumed version is greater. * it's assumed version is greater.
@ -366,7 +355,6 @@ find_repo_deps(struct xbps_handle *xhp,
error = true; error = true;
rv = ENODEV; rv = ENODEV;
} }
free(pkgname);
break; break;
default: default:
error = true; error = true;

View File

@ -40,7 +40,9 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
xbps_object_t obj; xbps_object_t obj;
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
const char *cfpkg, *repopkgver, *pkgver, *tract; const char *cfpkg, *repopkgver, *pkgver, *tract;
char *pkgname, *repopkgname, *buf; char pkgname[XBPS_NAME_SIZE];
char repopkgname[XBPS_NAME_SIZE];
char *buf;
pkg_cflicts = xbps_dictionary_get(pkg_repod, "conflicts"); pkg_cflicts = xbps_dictionary_get(pkg_repod, "conflicts");
if (xbps_array_count(pkg_cflicts) == 0) if (xbps_array_count(pkg_cflicts) == 0)
@ -54,8 +56,10 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts"); trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts");
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver); xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
repopkgname = xbps_pkg_name(repopkgver);
assert(repopkgname); if (!xbps_pkg_name(repopkgname, XBPS_NAME_SIZE, repopkgver)) {
abort();
}
iter = xbps_array_iterator(pkg_cflicts); iter = xbps_array_iterator(pkg_cflicts);
assert(iter); assert(iter);
@ -75,10 +79,10 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
/* Ignore itself */ /* Ignore itself */
xbps_dictionary_get_cstring_nocopy(pkgd, xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver); "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
if (strcmp(pkgname, repopkgname) == 0) { if (strcmp(pkgname, repopkgname) == 0) {
free(pkgname);
continue; continue;
} }
/* /*
@ -92,11 +96,9 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
!strcmp(tract, "update") || !strcmp(tract, "update") ||
!strcmp(tract, "remove") || !strcmp(tract, "remove") ||
!strcmp(tract, "hold")) { !strcmp(tract, "hold")) {
free(pkgname);
continue; continue;
} }
} }
free(pkgname);
xbps_dbg_printf(xhp, "found conflicting installed " xbps_dbg_printf(xhp, "found conflicting installed "
"pkg %s with pkg in transaction %s " "pkg %s with pkg in transaction %s "
"(matched by %s [trans])\n", pkgver, repopkgver, cfpkg); "(matched by %s [trans])\n", pkgver, repopkgver, cfpkg);
@ -123,13 +125,12 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
/* ignore itself */ /* ignore itself */
xbps_dictionary_get_cstring_nocopy(pkgd, xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver); "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
if (strcmp(pkgname, repopkgname) == 0) { if (strcmp(pkgname, repopkgname) == 0) {
free(pkgname);
continue; continue;
} }
free(pkgname);
xbps_dbg_printf(xhp, "found conflicting pkgs in " xbps_dbg_printf(xhp, "found conflicting pkgs in "
"transaction %s <-> %s (matched by %s [trans])\n", "transaction %s <-> %s (matched by %s [trans])\n",
pkgver, repopkgver, cfpkg); pkgver, repopkgver, cfpkg);
@ -144,7 +145,6 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
} }
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
free(repopkgname);
} }
static int static int
@ -156,7 +156,9 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
xbps_object_t obj2; xbps_object_t obj2;
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
const char *cfpkg, *repopkgver, *pkgver, *tract; const char *cfpkg, *repopkgver, *pkgver, *tract;
char *pkgname, *repopkgname, *buf; char pkgname[XBPS_NAME_SIZE];
char repopkgname[XBPS_NAME_SIZE];
char *buf;
pkg_cflicts = xbps_dictionary_get(obj, "conflicts"); pkg_cflicts = xbps_dictionary_get(obj, "conflicts");
if (xbps_array_count(pkg_cflicts) == 0) if (xbps_array_count(pkg_cflicts) == 0)
@ -164,12 +166,12 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts"); trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts");
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &repopkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &repopkgver);
repopkgname = xbps_pkg_name(repopkgver); if (!xbps_pkg_name(repopkgname, XBPS_NAME_SIZE, repopkgver)) {
assert(repopkgname); abort();
}
/* if a pkg is in the transaction, ignore the one from pkgdb */ /* if a pkg is in the transaction, ignore the one from pkgdb */
if (xbps_find_pkg_in_array(pkgs, repopkgname, NULL)) { if (xbps_find_pkg_in_array(pkgs, repopkgname, NULL)) {
free(repopkgname);
return 0; return 0;
} }
@ -189,13 +191,12 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
continue; continue;
} }
/* ignore itself */ /* ignore itself */
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
if (strcmp(pkgname, repopkgname) == 0) { if (strcmp(pkgname, repopkgname) == 0) {
free(pkgname);
continue; continue;
} }
free(pkgname);
xbps_dbg_printf(xhp, "found conflicting pkgs in " xbps_dbg_printf(xhp, "found conflicting pkgs in "
"transaction %s <-> %s (matched by %s [pkgdb])\n", "transaction %s <-> %s (matched by %s [pkgdb])\n",
pkgver, repopkgver, cfpkg); pkgver, repopkgver, cfpkg);
@ -210,7 +211,6 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
} }
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
free(repopkgname);
return 0; return 0;
} }

View File

@ -665,15 +665,16 @@ collect_binpkg_files(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod,
struct archive_entry *entry; struct archive_entry *entry;
struct stat st; struct stat st;
const char *pkgver; const char *pkgver;
char *bpkg, *pkgname; char *bpkg, pkgname[XBPS_NAME_SIZE];
/* size_t entry_size; */ /* size_t entry_size; */
int rv = 0, pkg_fd = -1; int rv = 0, pkg_fd = -1;
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
assert(pkgver); assert(pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
bpkg = xbps_repository_pkg_path(xhp, pkg_repod); bpkg = xbps_repository_pkg_path(xhp, pkg_repod);
if (bpkg == NULL) { if (bpkg == NULL) {
@ -750,7 +751,6 @@ out:
if (ar) if (ar)
archive_read_finish(ar); archive_read_finish(ar);
free(bpkg); free(bpkg);
free(pkgname);
return rv; return rv;
} }
@ -768,7 +768,7 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
xbps_dictionary_t pkgd, filesd; xbps_dictionary_t pkgd, filesd;
xbps_object_t obj; xbps_object_t obj;
const char *trans, *pkgver; const char *trans, *pkgver;
char *pkgname = NULL; char pkgname[XBPS_NAME_SIZE];
int rv = 0; int rv = 0;
unsigned int idx = 0; unsigned int idx = 0;
@ -795,9 +795,9 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
assert(pkgver); assert(pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
update = strcmp(trans, "update") == 0; update = strcmp(trans, "update") == 0;
if (update || (strcmp(trans, "install") == 0)) { if (update || (strcmp(trans, "install") == 0)) {
@ -828,8 +828,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
filesd = xbps_pkgdb_get_pkg_files(xhp, pkgname); filesd = xbps_pkgdb_get_pkg_files(xhp, pkgname);
if (filesd == NULL) { if (filesd == NULL) {
free(pkgname);
pkgname = NULL;
continue; continue;
} }
@ -841,8 +839,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
if (rv != 0) if (rv != 0)
goto out; goto out;
} }
free(pkgname);
pkgname = NULL;
} }
xbps_object_iterator_reset(iter); xbps_object_iterator_reset(iter);
@ -860,7 +856,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
} }
out: out:
free(pkgname);
if (rv != 0) if (rv != 0)
return rv; return rv;
return collect_obsoletes(xhp); return collect_obsoletes(xhp);

View File

@ -65,7 +65,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL; xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL;
xbps_array_t pkgs; xbps_array_t pkgs;
const char *repoloc, *repopkgver, *instpkgver, *reason; const char *repoloc, *repopkgver, *instpkgver, *reason;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
int action = 0, rv = 0; int action = 0, rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
bool autoinst = false, repolock = false; bool autoinst = false, repolock = false;
@ -75,9 +75,8 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
/* /*
* Find out if pkg is installed first. * Find out if pkg is installed first.
*/ */
if ((pkgname = xbps_pkg_name(pkg))) { if (xbps_pkg_name(pkgname, sizeof(pkgname), pkg)) {
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkgname); pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkgname);
free(pkgname);
} else { } else {
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg); pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkg);
} }
@ -187,22 +186,21 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
} }
} }
pkgname = xbps_pkg_name(repopkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), repopkgver)) {
assert(pkgname); abort();
}
/* /*
* Set package state in dictionary with same state than the * Set package state in dictionary with same state than the
* package currently uses, otherwise not-installed. * package currently uses, otherwise not-installed.
*/ */
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) { if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
if (rv != ENOENT) { if (rv != ENOENT) {
free(pkgname);
return rv; return rv;
} }
/* Package not installed, don't error out */ /* Package not installed, don't error out */
state = XBPS_PKG_STATE_NOT_INSTALLED; state = XBPS_PKG_STATE_NOT_INSTALLED;
} }
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) { if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) {
free(pkgname);
return rv; return rv;
} }
@ -218,15 +216,10 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall,
*/ */
if (!xbps_dictionary_set_cstring_nocopy(pkg_repod, if (!xbps_dictionary_set_cstring_nocopy(pkg_repod,
"transaction", reason)) { "transaction", reason)) {
free(pkgname);
return EINVAL; return EINVAL;
} }
if ((rv = xbps_transaction_store(xhp, pkgs, pkg_repod, reason, false)) != 0) {
free(pkgname); return xbps_transaction_store(xhp, pkgs, pkg_repod, reason, false);
return rv;
}
free(pkgname);
return 0;
} }
/* /*
@ -238,7 +231,7 @@ xbps_autoupdate(struct xbps_handle *xhp)
xbps_array_t rdeps; xbps_array_t rdeps;
xbps_dictionary_t pkgd; xbps_dictionary_t pkgd;
const char *pkgver; const char *pkgver;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
int rv; int rv;
/* /*
@ -250,11 +243,11 @@ xbps_autoupdate(struct xbps_handle *xhp)
return 0; return 0;
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
rv = trans_find_pkg(xhp, pkgname, false, false); rv = trans_find_pkg(xhp, pkgname, false, false);
free(pkgname);
xbps_dbg_printf(xhp, "%s: trans_find_pkg xbps: %d\n", __func__, rv); xbps_dbg_printf(xhp, "%s: trans_find_pkg xbps: %d\n", __func__, rv);
@ -266,15 +259,15 @@ xbps_autoupdate(struct xbps_handle *xhp)
rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, "xbps"); rdeps = xbps_pkgdb_get_pkg_revdeps(xhp, "xbps");
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) { for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
const char *curpkgver = NULL; const char *curpkgver = NULL;
char *curpkgn; char curpkgn[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver); xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
xbps_dbg_printf(xhp, "%s: processing revdep %s\n", __func__, curpkgver); xbps_dbg_printf(xhp, "%s: processing revdep %s\n", __func__, curpkgver);
curpkgn = xbps_pkg_name(curpkgver); if (!xbps_pkg_name(curpkgn, sizeof(curpkgn), curpkgver)) {
assert(curpkgn); abort();
}
rv = trans_find_pkg(xhp, curpkgn, false, false); rv = trans_find_pkg(xhp, curpkgn, false, false);
free(curpkgn);
xbps_dbg_printf(xhp, "%s: trans_find_pkg revdep %s: %d\n", __func__, curpkgver, rv); xbps_dbg_printf(xhp, "%s: trans_find_pkg revdep %s: %d\n", __func__, curpkgver, rv);
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
return -1; return -1;
@ -305,12 +298,9 @@ xbps_autoupdate(struct xbps_handle *xhp)
int int
xbps_transaction_update_packages(struct xbps_handle *xhp) xbps_transaction_update_packages(struct xbps_handle *xhp)
{ {
xbps_dictionary_t pkgd;
xbps_object_t obj; xbps_object_t obj;
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
const char *pkgver; bool newpkg_found = false;
char *pkgname;
bool hold, newpkg_found = false;
int rv = 0; int rv = 0;
rv = xbps_autoupdate(xhp); rv = xbps_autoupdate(xhp);
@ -329,7 +319,11 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
assert(iter); assert(iter);
while ((obj = xbps_object_iterator_next(iter))) { while ((obj = xbps_object_iterator_next(iter))) {
hold = false; xbps_dictionary_t pkgd;
const char *pkgver;
char pkgname[XBPS_NAME_SIZE];
bool hold = false;
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj); pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver))
continue; continue;
@ -338,8 +332,9 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
xbps_dbg_printf(xhp, "[rpool] package `%s' " xbps_dbg_printf(xhp, "[rpool] package `%s' "
"on hold, ignoring updates.\n", pkgver); "on hold, ignoring updates.\n", pkgver);
} }
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
rv = trans_find_pkg(xhp, pkgname, false, hold); rv = trans_find_pkg(xhp, pkgname, false, hold);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv); xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
if (rv == 0) { if (rv == 0) {
@ -351,7 +346,6 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
*/ */
rv = 0; rv = 0;
} }
free(pkgname);
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
@ -385,15 +379,15 @@ xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg)
rdeps = NULL; rdeps = NULL;
} }
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) { for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
const char *curpkgver = NULL; const char *pkgver = NULL;
char *curpkgn; char pkgname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver); xbps_array_get_cstring_nocopy(rdeps, i, &pkgver);
curpkgn = xbps_pkg_name(curpkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(curpkgn); abort();
rv = trans_find_pkg(xhp, curpkgn, false, false); }
free(curpkgn); rv = trans_find_pkg(xhp, pkgname, false, false);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, curpkgver, rv); xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
return rv; return rv;
} }
@ -429,15 +423,15 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg,
rdeps = NULL; rdeps = NULL;
} }
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) { for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
const char *curpkgver = NULL; const char *pkgver = NULL;
char *curpkgn; char pkgname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver); xbps_array_get_cstring_nocopy(rdeps, i, &pkgver);
curpkgn = xbps_pkg_name(curpkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(curpkgn); abort();
rv = trans_find_pkg(xhp, curpkgn, false, false); }
free(curpkgn); rv = trans_find_pkg(xhp, pkgname, false, false);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, curpkgver, rv); xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
return rv; return rv;
} }

View File

@ -41,7 +41,7 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_object_t obj, obj2; xbps_object_t obj, obj2;
xbps_object_iterator_t iter; xbps_object_iterator_t iter;
const char *pkgver; const char *pkgver;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
obj = xbps_array_get(pkgs, i); obj = xbps_array_get(pkgs, i);
replaces = xbps_dictionary_get(obj, "replaces"); replaces = xbps_dictionary_get(obj, "replaces");
@ -52,13 +52,14 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
assert(iter); assert(iter);
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
while ((obj2 = xbps_object_iterator_next(iter)) != NULL) { while ((obj2 = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_t instd, reppkgd; xbps_dictionary_t instd, reppkgd;
const char *pattern = NULL, *curpkgver = NULL; const char *pattern = NULL, *curpkgver = NULL;
char *curpkgname; char curpkgname[XBPS_NAME_SIZE];
bool instd_auto = false, hold = false; bool instd_auto = false, hold = false;
pattern = xbps_string_cstring_nocopy(obj2); pattern = xbps_string_cstring_nocopy(obj2);
@ -76,14 +77,14 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
if (xbps_dictionary_get_bool(instd, "hold", &hold) && hold) if (xbps_dictionary_get_bool(instd, "hold", &hold) && hold)
continue; continue;
curpkgname = xbps_pkg_name(curpkgver); if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
assert(curpkgname); abort();
}
/* /*
* Check that we are not replacing the same package, * Check that we are not replacing the same package,
* due to virtual packages. * due to virtual packages.
*/ */
if (strcmp(pkgname, curpkgname) == 0) { if (strcmp(pkgname, curpkgname) == 0) {
free(curpkgname);
continue; continue;
} }
/* /*
@ -143,14 +144,10 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_dictionary_set_bool(instd, "replaced", true); xbps_dictionary_set_bool(instd, "replaced", true);
if (!xbps_array_add_first(pkgs, instd)) { if (!xbps_array_add_first(pkgs, instd)) {
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
free(pkgname);
free(curpkgname);
return EINVAL; return EINVAL;
} }
free(curpkgname);
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
free(pkgname);
} }
return 0; return 0;

View File

@ -131,12 +131,12 @@ compute_transaction_stats(struct xbps_handle *xhp)
*/ */
if ((strcmp(tract, "remove") == 0) || if ((strcmp(tract, "remove") == 0) ||
((strcmp(tract, "update") == 0) && !preserve)) { ((strcmp(tract, "update") == 0) && !preserve)) {
char *pkgname; char pkgname[XBPS_NAME_SIZE];
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
pkg_metad = xbps_pkgdb_get_pkg(xhp, pkgname); pkg_metad = xbps_pkgdb_get_pkg(xhp, pkgname);
free(pkgname);
if (pkg_metad == NULL) if (pkg_metad == NULL)
continue; continue;
xbps_dictionary_get_uint64(pkg_metad, xbps_dictionary_get_uint64(pkg_metad,

View File

@ -52,28 +52,30 @@ check_virtual_pkgs(xbps_array_t mdeps,
for (unsigned int i = 0; i < xbps_array_count(provides); i++) { for (unsigned int i = 0; i < xbps_array_count(provides); i++) {
xbps_array_t rundeps; xbps_array_t rundeps;
const char *pkgver, *revpkgver, *pkgpattern; const char *pkgver, *revpkgver, *pkgpattern;
char *pkgname, *vpkgname, *vpkgver, *str; char pkgname[XBPS_NAME_SIZE], vpkgname[XBPS_NAME_SIZE];
char *vpkgver = NULL, *str = NULL;
pkgver = revpkgver = pkgpattern = NULL; pkgver = revpkgver = pkgpattern = NULL;
pkgname = vpkgname = vpkgver = str = NULL;
xbps_dictionary_get_cstring_nocopy(trans_pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(trans_pkgd, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(rev_pkgd, "pkgver", &revpkgver); xbps_dictionary_get_cstring_nocopy(rev_pkgd, "pkgver", &revpkgver);
xbps_array_get_cstring(provides, i, &vpkgver); xbps_array_get_cstring(provides, i, &vpkgver);
vpkgname = xbps_pkg_name(vpkgver);
assert(vpkgname); if (!xbps_pkg_name(vpkgname, sizeof(vpkgname), vpkgver)) {
break;
}
rundeps = xbps_dictionary_get(rev_pkgd, "run_depends"); rundeps = xbps_dictionary_get(rev_pkgd, "run_depends");
for (unsigned int x = 0; x < xbps_array_count(rundeps); x++) { for (unsigned int x = 0; x < xbps_array_count(rundeps); x++) {
xbps_array_get_cstring_nocopy(rundeps, x, &pkgpattern); xbps_array_get_cstring_nocopy(rundeps, x, &pkgpattern);
if (((pkgname = xbps_pkgpattern_name(pkgpattern)) == NULL) &&
((pkgname = xbps_pkg_name(pkgpattern)) == NULL)) if ((!xbps_pkgpattern_name(pkgname, sizeof(pkgname), pkgpattern)) &&
(!xbps_pkg_name(pkgname, sizeof(pkgname), pkgpattern)))
continue; continue;
if (strcmp(vpkgname, pkgname)) { if (strcmp(vpkgname, pkgname)) {
free(pkgname);
continue; continue;
} }
free(pkgname);
if (!strcmp(vpkgver, pkgpattern) || if (!strcmp(vpkgver, pkgpattern) ||
xbps_pkgpattern_match(vpkgver, pkgpattern)) { xbps_pkgpattern_match(vpkgver, pkgpattern)) {
continue; continue;
@ -85,7 +87,6 @@ check_virtual_pkgs(xbps_array_t mdeps,
free(str); free(str);
matched = true; matched = true;
} }
free(vpkgname);
free(vpkgver); free(vpkgver);
} }
return matched; return matched;
@ -112,7 +113,7 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_array_t pkgrdeps; xbps_array_t pkgrdeps;
xbps_object_t obj; xbps_object_t obj;
const char *pkgver, *tract; const char *pkgver, *tract;
char *pkgname; char pkgname[XBPS_NAME_SIZE];
obj = xbps_array_get(pkgs, i); obj = xbps_array_get(pkgs, i);
/* /*
@ -129,10 +130,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
continue; continue;
} }
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
if (xbps_pkg_is_installed(xhp, pkgname) == 0) { if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
free(pkgname);
continue; continue;
} }
/* /*
@ -141,13 +143,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
*/ */
pkgrdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname); pkgrdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
if (!xbps_array_count(pkgrdeps)) { if (!xbps_array_count(pkgrdeps)) {
free(pkgname);
continue; continue;
} }
/* /*
* If pkg is ignored, pass to the next one. * If pkg is ignored, pass to the next one.
*/ */
free(pkgname);
if (xbps_pkg_is_ignored(xhp, pkgver)) { if (xbps_pkg_is_ignored(xhp, pkgver)) {
continue; continue;
} }
@ -159,12 +159,15 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_array_t rundeps; xbps_array_t rundeps;
xbps_dictionary_t revpkgd; xbps_dictionary_t revpkgd;
const char *curpkgver = NULL, *revpkgver, *curdep = NULL, *curtract; const char *curpkgver = NULL, *revpkgver, *curdep = NULL, *curtract;
char *curpkgname, *curdepname; char curpkgname[XBPS_NAME_SIZE];
char curdepname[XBPS_NAME_SIZE];
bool found = false; bool found = false;
xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver); xbps_array_get_cstring_nocopy(pkgrdeps, x, &curpkgver);
pkgname = xbps_pkg_name(curpkgver);
assert(pkgname); if (!xbps_pkg_name(pkgname, sizeof(pkgname), curpkgver)) {
abort();
}
if ((revpkgd = xbps_find_pkg_in_array(pkgs, pkgname, NULL))) { if ((revpkgd = xbps_find_pkg_in_array(pkgs, pkgname, NULL))) {
xbps_dictionary_get_cstring_nocopy(revpkgd, "transaction", &curtract); xbps_dictionary_get_cstring_nocopy(revpkgd, "transaction", &curtract);
if (strcmp(curtract, "remove") == 0) if (strcmp(curtract, "remove") == 0)
@ -181,14 +184,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
*/ */
if (strcmp(tract, "remove") == 0) { if (strcmp(tract, "remove") == 0) {
if (xbps_dictionary_get(obj, "replaced")) { if (xbps_dictionary_get(obj, "replaced")) {
free(pkgname);
continue; continue;
} }
if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) { if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) {
free(pkgname);
continue; continue;
} }
free(pkgname);
broken_pkg(mdeps, curpkgver, pkgver, tract); broken_pkg(mdeps, curpkgver, pkgver, tract);
continue; continue;
} }
@ -196,7 +196,6 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
* First try to match any supported virtual package. * First try to match any supported virtual package.
*/ */
if (check_virtual_pkgs(mdeps, obj, revpkgd)) { if (check_virtual_pkgs(mdeps, obj, revpkgd)) {
free(pkgname);
continue; continue;
} }
/* /*
@ -206,30 +205,26 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
/* /*
* Find out what dependency is it. * Find out what dependency is it.
*/ */
curpkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver)) {
assert(curpkgname); abort();
}
for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) { for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) {
xbps_array_get_cstring_nocopy(rundeps, j, &curdep); xbps_array_get_cstring_nocopy(rundeps, j, &curdep);
if (((curdepname = xbps_pkg_name(curdep)) == NULL) && if ((!xbps_pkgpattern_name(curdepname, sizeof(curdepname), curdep)) &&
((curdepname = xbps_pkgpattern_name(curdep)) == NULL)) (!xbps_pkg_name(curdepname, sizeof(curdepname), curdep))) {
abort(); abort();
}
if (strcmp(curdepname, curpkgname) == 0) { if (strcmp(curdepname, curpkgname) == 0) {
free(curdepname);
found = true; found = true;
break; break;
} }
free(curdepname);
} }
free(curpkgname);
if (!found) { if (!found) {
free(pkgname);
continue; continue;
} }
if (xbps_match_pkgdep_in_array(rundeps, pkgver)) { if (xbps_match_pkgdep_in_array(rundeps, pkgver)) {
free(pkgname);
continue; continue;
} }
/* /*
@ -239,10 +234,8 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
* is in the transaction. * is in the transaction.
*/ */
if (xbps_find_pkg_in_array(pkgs, pkgname, "update")) { if (xbps_find_pkg_in_array(pkgs, pkgname, "update")) {
free(pkgname);
continue; continue;
} }
free(pkgname);
broken_pkg(mdeps, curpkgver, pkgver, tract); broken_pkg(mdeps, curpkgver, pkgver, tract);
} }

View File

@ -83,24 +83,23 @@ collect_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, bool req)
assert(iter); assert(iter);
while ((obj = xbps_object_iterator_next(iter))) { while ((obj = xbps_object_iterator_next(iter))) {
const char *trans = NULL; const char *trans = NULL;
char *pkgname = NULL; char pkgname[XBPS_NAME_SIZE];
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver))
continue; continue;
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
assert(pkgname); abort();
}
/* ignore shlibs if pkg is on hold mode */ /* ignore shlibs if pkg is on hold mode */
if (xbps_dictionary_get_cstring_nocopy(obj, "transaction", &trans)) { if (xbps_dictionary_get_cstring_nocopy(obj, "transaction", &trans)) {
if (!strcmp(trans, "hold")) { if (!strcmp(trans, "hold")) {
free(pkgname);
continue; continue;
} }
} }
xbps_dictionary_set(pd, pkgname, obj); xbps_dictionary_set(pd, pkgname, obj);
free(pkgname);
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);

View File

@ -36,7 +36,7 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
{ {
xbps_array_t replaces; xbps_array_t replaces;
const char *pkgver, *repo; const char *pkgver, *repo;
char *pkgname, *self_replaced; char pkgname[XBPS_NAME_SIZE], *self_replaced;
xbps_dictionary_get_cstring_nocopy(pkgd, "repository", &repo); xbps_dictionary_get_cstring_nocopy(pkgd, "repository", &repo);
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
@ -54,10 +54,10 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs,
if ((replaces = xbps_dictionary_get(pkgd, "replaces")) == NULL) if ((replaces = xbps_dictionary_get(pkgd, "replaces")) == NULL)
replaces = xbps_array_create(); replaces = xbps_array_create();
pkgname = xbps_pkg_name(pkgver); if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
assert(pkgname); abort();
}
self_replaced = xbps_xasprintf("%s>=0", pkgname); self_replaced = xbps_xasprintf("%s>=0", pkgname);
free(pkgname);
xbps_array_add_cstring(replaces, self_replaced); xbps_array_add_cstring(replaces, self_replaced);
free(self_replaced); free(self_replaced);

View File

@ -106,7 +106,7 @@ xbps_pkg_is_installed(struct xbps_handle *xhp, const char *pkg)
bool bool
xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg) xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg)
{ {
char *pkgname; char pkgname[XBPS_NAME_SIZE];
bool rv = false; bool rv = false;
assert(xhp); assert(xhp);
@ -115,10 +115,9 @@ xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg)
if (!xhp->ignored_pkgs) if (!xhp->ignored_pkgs)
return false; return false;
if ((pkgname = xbps_pkgpattern_name(pkg)) != NULL || if (xbps_pkgpattern_name(pkgname, XBPS_NAME_SIZE, pkg) ||
(pkgname = xbps_pkg_name(pkg)) != NULL) { xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkg)) {
rv = xbps_match_string_in_array(xhp->ignored_pkgs, pkgname); rv = xbps_match_string_in_array(xhp->ignored_pkgs, pkgname);
free(pkgname);
return rv; return rv;
} }
@ -246,21 +245,22 @@ xbps_pkg_revision(const char *pkg)
return NULL; return NULL;
} }
char * bool
xbps_pkg_name(const char *pkg) xbps_pkg_name(char *dst, size_t len, const char *pkg)
{ {
const char *p, *r; const char *p, *r;
char *buf; size_t plen;
unsigned int len;
size_t p_len;
bool valid = false; bool valid = false;
if ((p = strrchr(pkg, '-')) == NULL) assert(dst);
return NULL; assert(pkg);
p_len = strlen(p); if ((p = strrchr(pkg, '-')) == NULL)
return false;
plen = strlen(p);
/* i = 1 skips first '-' */ /* i = 1 skips first '-' */
for (unsigned int i = 1; i < p_len; i++) { for (unsigned int i = 1; i < plen; i++) {
if (p[i] == '_') if (p[i] == '_')
break; break;
if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) { if (isdigit((unsigned char)p[i]) && (r = strchr(p + i + 1, '_'))) {
@ -269,43 +269,44 @@ xbps_pkg_name(const char *pkg)
} }
} }
if (!valid) if (!valid)
return NULL; return false;
len = strlen(pkg) - strlen(p) + 1; plen = strlen(pkg) - strlen(p) + 1;
buf = malloc(len); if (plen > len)
assert(buf != NULL); return false;
memcpy(buf, pkg, len-1); memcpy(dst, pkg, plen-1);
buf[len-1] = '\0'; dst[plen-1] = '\0';
return buf; return true;
} }
char * bool
xbps_pkgpattern_name(const char *pkg) xbps_pkgpattern_name(char *dst, size_t len, const char *pkg)
{ {
char *res, *pkgname; const char *res;
unsigned int len; size_t plen;
assert(pkg != NULL); assert(dst);
assert(pkg);
if ((res = strpbrk(pkg, "><*?[]")) == NULL) if ((res = strpbrk(pkg, "><*?[]")) == NULL)
return NULL; return false;
len = strlen(pkg) - strlen(res) + 1; plen = strlen(pkg) - strlen(res) + 1;
if (strlen(pkg) < len-2) if (strlen(pkg) < plen-2)
return NULL; return false;
if (pkg[len-2] == '-') if (pkg[plen-2] == '-')
len--; plen--;
pkgname = malloc(len); if (plen > len)
assert(pkgname != NULL); return false;
memcpy(pkgname, pkg, len-1); memcpy(dst, pkg, plen-1);
pkgname[len-1] = '\0'; dst[plen-1] = '\0';
return pkgname; return true;
} }
const char * const char *

View File

@ -36,49 +36,61 @@ ATF_TC_HEAD(util_test, tc)
ATF_TC_BODY(util_test, tc) ATF_TC_BODY(util_test, tc)
{ {
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-a"), NULL); char name[XBPS_NAME_SIZE];
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-1"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi"), NULL); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-a"), false);
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi-7.8"), NULL); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-1"), false);
ATF_CHECK_EQ(xbps_pkg_name("python-e_dbus"), NULL); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-100dpi"), false);
ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v1"), NULL); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-100dpi-7.8"), false);
ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v_1"), NULL); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "python-e_dbus"), false);
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi-1.8_blah"), NULL); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "fs-utils-v1"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "fs-utils-v_1"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-100dpi-1.8_blah"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "perl-PerlIO-utf8_strict"), false);
ATF_CHECK_EQ(xbps_pkg_version("perl-PerlIO-utf8_strict"), NULL); ATF_CHECK_EQ(xbps_pkg_version("perl-PerlIO-utf8_strict"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi"), NULL); ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-7.8"), NULL); ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-7.8"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus"), NULL); ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus-1"), NULL); ATF_CHECK_EQ(xbps_pkg_version("python-e_dbus-1"), NULL);
ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-1.8_blah"), NULL); ATF_CHECK_EQ(xbps_pkg_version("font-adobe-100dpi-1.8_blah"), NULL);
ATF_REQUIRE_STREQ(xbps_pkg_name("font-adobe-100dpi-7.8_2"), "font-adobe-100dpi");
ATF_REQUIRE_STREQ(xbps_pkg_name("systemd-43_1"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkg_name("python-e_dbus-1.0_1"), "python-e_dbus");
ATF_REQUIRE_STREQ(xbps_pkg_name("perl-Module-CoreList-5.20170715_24_1"), "perl-Module-CoreList");
ATF_REQUIRE_STREQ(xbps_pkg_name("perl-PerlIO-utf8_strict-0.007_1"), "perl-PerlIO-utf8_strict");
ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-7.8_2"), "7.8_2"); ATF_REQUIRE_STREQ(xbps_pkg_version("font-adobe-100dpi-7.8_2"), "7.8_2");
ATF_REQUIRE_STREQ(xbps_pkg_version("python-e_dbus-1_1"), "1_1"); ATF_REQUIRE_STREQ(xbps_pkg_version("python-e_dbus-1_1"), "1_1");
ATF_REQUIRE_STREQ(xbps_pkg_version("fs-utils-v1_1"), "v1_1"); ATF_REQUIRE_STREQ(xbps_pkg_version("fs-utils-v1_1"), "v1_1");
ATF_REQUIRE_STREQ(xbps_pkg_version("perl-Digest-1.17_01_1"), "1.17_01_1"); ATF_REQUIRE_STREQ(xbps_pkg_version("perl-Digest-1.17_01_1"), "1.17_01_1");
ATF_REQUIRE_STREQ(xbps_pkg_version("perl-PerlIO-utf8_strict-0.007_1"), "0.007_1"); ATF_REQUIRE_STREQ(xbps_pkg_version("perl-PerlIO-utf8_strict-0.007_1"), "0.007_1");
ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd_21-43_0"), "0"); ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd_21-43_0"), "0");
ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd-43_1_0"), "0"); ATF_REQUIRE_STREQ(xbps_pkg_revision("systemd-43_1_0"), "0");
ATF_REQUIRE_STREQ(xbps_pkg_revision("perl-Module-CoreList-5.20170715_24_1"), "1"); ATF_REQUIRE_STREQ(xbps_pkg_revision("perl-Module-CoreList-5.20170715_24_1"), "1");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>=43"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>43"), "systemd"); ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd>=43"), true);
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<43"), "systemd"); ATF_REQUIRE_STREQ(name, "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<=43"), "systemd"); ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd>43"), true);
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd-[0-9]*"), "systemd"); ATF_REQUIRE_STREQ(name, "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>4[3-9]?"), "systemd"); ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd<43"), true);
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<4_1?"), "systemd"); ATF_REQUIRE_STREQ(name, "systemd");
ATF_CHECK_EQ(xbps_pkgpattern_name("*nslookup"), NULL); ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd<=43"), true);
ATF_REQUIRE_STREQ(name, "systemd");
ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd>4[3-9]?"), true);
ATF_REQUIRE_STREQ(name, "systemd");
ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd<4_1?"), true);
ATF_REQUIRE_STREQ(name, "systemd");
ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "systemd-[0-9]*"), true);
ATF_REQUIRE_STREQ(name, "systemd");
ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "*nslookup"), false);
ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64.xbps"), "x86_64"); ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64.xbps"), "x86_64");
ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl"); ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl");
ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl"); ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl");
ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64.xbps"), "x86_64"); ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64.xbps"), "x86_64");
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64.xbps"), "foo-1.0_1"); ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64.xbps"), "foo-1.0_1");
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1"); ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1");
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64.xbps"), "foo-1.0_1"); ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64.xbps"), "foo-1.0_1");
ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1"); ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1");
ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64.xbps"), NULL); ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64.xbps"), NULL);
ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64"), NULL); ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64"), NULL);
} }