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 *buildopts, *shlib_provides, *shlib_requires, *alternatives;
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;
int c, pkg_fd;
mode_t myumask;
@ -947,8 +947,7 @@ main(int argc, char **argv)
/*
* Sanity check for required options.
*/
pkgname = xbps_pkg_name(pkgver);
if (pkgname == NULL)
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
die("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver);
version = xbps_pkg_version(pkgver);
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;
const char *instver, *newver;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
int rv = 0;
bool slog = false;
@ -99,8 +99,9 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata UNUSED)
/* empty */
break;
case XBPS_STATE_UPDATE:
pkgname = xbps_pkg_name(xscd->arg);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), xscd->arg)) {
abort();
}
newver = xbps_pkg_version(xscd->arg);
pkgd = xbps_pkgdb_get_pkg(xscd->xhp, pkgname);
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,
xscd->xhp->rootdir);
}
free(pkgname);
break;
/* success */
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) {
xbps_dictionary_t ipkgd;
const char *ipkgver, *iversion, *version;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
/* get installed pkgver */
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname);
assert(ipkgd);
xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver);
version = xbps_pkg_version(pkgver);
iversion = xbps_pkg_version(ipkgver);
buf = xbps_xasprintf("%s (%s -> %s)", pkgname, iversion, version);
free(pkgname);
}
if ((match && (strcmp(match, tract) == 0)) || (!match && dload)) {
if (buf) {

View File

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

View File

@ -43,19 +43,19 @@ pkgdb_cb(struct xbps_handle *xhp UNUSED,
bool *done UNUSED)
{
const char *pkgver = NULL;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
int rv, *errors = (int *)arg;
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (xhp->flags & XBPS_FLAG_VERBOSE)
printf("Checking %s ...\n", pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
if ((rv = check_pkg_integrity(xhp, obj, pkgname)) != 0)
*errors += 1;
free(pkgname);
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++) {
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);
/*
@ -272,8 +273,9 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
free(pkgver);
continue;
}
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
/*
* Check if this package exists already in the index, but first
* 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;
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
goto out;
}
} else if (!force) {
@ -320,7 +321,6 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
free(opkgver);
free(oarch);
free(pkgver);
free(pkgname);
continue;
}
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) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
goto out;
}
@ -342,7 +341,6 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
xbps_object_release(binpkgd);
free(sha256);
free(pkgver);
free(pkgname);
rv = EINVAL;
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) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
goto out;
}
if (!xbps_dictionary_set_uint64(binpkgd, "filename-size", (uint64_t)st.st_size)) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
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)) {
xbps_object_release(binpkgd);
free(pkgname);
free(pkgver);
rv = EINVAL;
goto out;
}
xbps_object_release(binpkgd);
free(pkgname);
free(pkgver);
}
/*

View File

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

View File

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

View File

@ -43,6 +43,7 @@
#include <archive_entry.h>
#define XBPS_MAXPATH 512
#define XBPS_NAME_SIZE 64
/**
* @file include/xbps.h
@ -50,7 +51,7 @@
*
* This header documents the full API for the XBPS Library.
*/
#define XBPS_API_VERSION "20200118"
#define XBPS_API_VERSION "20200208"
#ifndef XBPS_VERSION
#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>
* 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
* errno is set appropiately. The pointer should be free(3)d when it's
* no longer needed.
* @return true on success, false otherwise.
*/
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
* 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
* 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.
*
* @return A pointer to a malloc(3)ed string with the package name,
* NULL otherwise and errno is set appropiately. The pointer should be
* free(3)d when it's no longer needed.
* @return true on success, false otherwise.
*/
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>.

View File

@ -2,8 +2,8 @@
RANLIB ?= ranlib
LIBXBPS_MAJOR = 4
LIBXBPS_MINOR = 1
LIBXBPS_MAJOR = 5
LIBXBPS_MINOR = 0
LIBXBPS_MICRO = 0
LIBXBPS_SHLIB = libxbps.so.$(LIBXBPS_MAJOR).$(LIBXBPS_MINOR).$(LIBXBPS_MICRO)
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_dictionary_t alternatives, pkg_alternatives;
const char *pkgver;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
bool update = false;
int rv = 0;
@ -346,7 +346,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
return 0;
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;
xbps_dictionary_get_bool(pkgd, "alternatives-update", &update);
@ -396,7 +396,6 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
break;
}
xbps_object_release(allkeys);
free(pkgname);
return rv;
}
@ -410,7 +409,7 @@ xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
*/
static void
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;
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_dictionary_t alternatives, pkg_alternatives;
const char *pkgver;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
int rv = 0;
assert(xhp);
@ -551,8 +550,7 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
assert(alternatives);
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver);
if (pkgname == NULL)
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
return EINVAL;
/*
@ -612,7 +610,6 @@ xbps_alternatives_register(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
break;
}
xbps_object_release(allkeys);
free(pkgname);
return rv;
}

View File

@ -90,28 +90,26 @@ xbps_configure_pkg(struct xbps_handle *xhp,
bool update)
{
xbps_dictionary_t pkgd;
char *pkgname;
const char *p;
char pkgname[XBPS_NAME_SIZE];
int rv = 0;
pkg_state_t state = 0;
mode_t myumask;
assert(pkgver != NULL);
if ((pkgname = xbps_pkg_name(pkgver)) == NULL) {
xbps_dbg_printf(xhp, "[configure] cannot guess "
"pkgname for %s\n", pkgver);
/* assume pkgver == pkgname */
pkgname = strdup(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
p = pkgver;
} else {
p = pkgname;
}
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
pkgd = xbps_pkgdb_get_pkg(xhp, p);
if (pkgd == NULL) {
xbps_dbg_printf(xhp, "[configure] cannot find %s (%s) "
"in pkgdb\n", pkgname, pkgver);
free(pkgname);
"in pkgdb\n", p, pkgver);
return ENOENT;
}
free(pkgname);
rv = xbps_pkg_state_dictionary(pkgd, &state);
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;
struct item *item, *xitem;
const char *pkgver = NULL;
char *pkgn;
char pkgn[XBPS_NAME_SIZE];
assert(xhp);
assert(pkgd);
@ -154,8 +154,9 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
provides = xbps_dictionary_get(pkgd, "provides");
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgn = xbps_pkg_name(pkgver);
assert(pkgn);
if (!xbps_pkg_name(pkgn, sizeof(pkgn), pkgver)) {
abort();
}
item = lookupItem(pkgn);
if (item) {
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->pkgver = pkgver;
assert(item);
free(pkgn);
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
xbps_dictionary_t curpkgd;
const char *curdep = NULL;
char *curdepname;
char curdepname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curdep);
if (rpool) {
@ -189,15 +189,14 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
errno = ENODEV;
return NULL;
}
if ((curdepname = xbps_pkgpattern_name(curdep)) == NULL)
curdepname = xbps_pkg_name(curdep);
assert(curdepname);
if ((!xbps_pkgpattern_name(curdepname, XBPS_NAME_SIZE, curdep)) &&
(!xbps_pkg_name(curdepname, XBPS_NAME_SIZE, curdep))) {
abort();
}
if (provides && xbps_match_pkgname_in_array(provides, curdepname)) {
xbps_dbg_printf(xhp, "%s: ignoring dependency %s "
"already in provides\n", pkgver, curdep);
free(curdepname);
continue;
}
xitem = lookupItem(curdepname);
@ -214,7 +213,6 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool,
}
assert(xitem);
addDepn(item, xitem);
free(curdepname);
}
/* all deps were processed, add item to head */
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_dictionary_t pkgd;
char outstr[64];
char outstr[64], pkgname[XBPS_NAME_SIZE];
time_t t;
struct tm tm;
struct tm *tmp;
const char *pkgver;
char *pkgname = NULL, *buf, *sha256;
char *buf, *sha256;
int rv = 0;
bool autoinst = false;
@ -51,8 +51,11 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
pkgd = xbps_dictionary_copy_mutable(pkgrd);
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
xbps_dbg_printf(xhp, "%s: invalid pkgname %s\n", __func__, pkgver);
rv = EINVAL;
goto out;
}
if (xhp->flags & XBPS_FLAG_INSTALL_AUTO)
autoinst = true;
@ -130,8 +133,6 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
}
out:
xbps_object_release(pkgd);
if (pkgname)
free(pkgname);
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_array_t obsoletes = NULL;
char *pkgname, metafile[PATH_MAX];
char pkgname[XBPS_NAME_SIZE], metafile[PATH_MAX];
int rv = 0;
pkg_state_t state = 0;
uid_t euid;
@ -119,8 +119,9 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
assert(xhp);
assert(pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
euid = geteuid();
@ -181,7 +182,6 @@ xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update)
* overwritten later in unpack phase.
*/
if (update) {
free(pkgname);
return 0;
}
@ -259,8 +259,6 @@ purge:
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL);
xbps_dictionary_remove(xhp->pkgdb, pkgname);
out:
if (pkgname != NULL)
free(pkgname);
if (rv != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver,
"%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",
NULL
};
char *pkgname, *fpath;
char pkgname[XBPS_NAME_SIZE], *fpath;
int fd, rv;
assert(blob);
@ -103,8 +103,9 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
close(fd);
/* exec script */
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
version = xbps_pkg_version(pkgver);
assert(version);
@ -129,7 +130,6 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
} else {
rv = -1;
}
free(pkgname);
out:
remove(fpath);

View File

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

View File

@ -84,7 +84,7 @@ unpack_archive(struct xbps_handle *xhp,
size_t instbufsiz = 0, rembufsiz = 0;
ssize_t entry_size;
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;
bool preserve, update, file_exists, keep_conf_file;
bool skip_extract, force, xucd_stats;
@ -102,8 +102,9 @@ unpack_archive(struct xbps_handle *xhp,
euid = geteuid();
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
if (xhp->flags & XBPS_FLAG_FORCE_UNPACK)
force = true;
@ -550,8 +551,6 @@ out:
xbps_object_release(binpkg_propsd);
if (xbps_object_type(binpkg_filesd) == XBPS_TYPE_DICTIONARY)
xbps_object_release(binpkg_filesd);
if (pkgname != NULL)
free(pkgname);
if (instbuf != NULL)
free(instbuf);
if (rembuf != NULL)

View File

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

View File

@ -225,7 +225,7 @@ array_replace_dict(xbps_array_t array,
{
xbps_object_t obj;
const char *curpkgver;
char *curpkgname;
char curpkgname[XBPS_NAME_SIZE];
assert(xbps_object_type(array) == XBPS_TYPE_ARRAY);
assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY);
@ -249,17 +249,15 @@ array_replace_dict(xbps_array_t array,
/* pkgname match */
xbps_dictionary_get_cstring_nocopy(obj,
"pkgver", &curpkgver);
curpkgname = xbps_pkg_name(curpkgver);
assert(curpkgname);
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
abort();
}
if (strcmp(curpkgname, str) == 0) {
if (!xbps_array_set(array, i, dict)) {
free(curpkgname);
return EINVAL;
}
free(curpkgname);
return 0;
}
free(curpkgname);
}
}
/* 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))) {
const char *pkgver;
char *dpkgn;
char dpkgn[XBPS_NAME_SIZE];
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,
"pkgver", &pkgver))
continue;
dpkgn = xbps_pkg_name(pkgver);
assert(dpkgn);
if (!xbps_pkg_name(dpkgn, sizeof(dpkgn), pkgver)) {
abort();
}
if (strcmp(dpkgn, str) == 0) {
free(dpkgn);
found = true;
break;
}
free(dpkgn);
}
}
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;
const char *pkgver = NULL;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
/* exact match by pkgver */
if ((pkgname = xbps_pkg_name(p)) == NULL)
if (!xbps_pkg_name(pkgname, sizeof(pkgname), p))
return NULL;
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;
}
@ -163,12 +161,11 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p)
{
xbps_dictionary_t d = NULL;
const char *pkgver = NULL;
char *pkgname = NULL;
char pkgname[XBPS_NAME_SIZE];
/* match by pkgpattern in pkgver */
if ((pkgname = xbps_pkgpattern_name(p)) == NULL) {
if ((pkgname = xbps_pkg_name(p))) {
free(pkgname);
if (!xbps_pkgpattern_name(pkgname, sizeof(pkgname), p)) {
if (xbps_pkg_name(pkgname, sizeof(pkgname), p)) {
return match_pkg_by_pkgver(repod, p);
}
return NULL;
@ -184,7 +181,6 @@ match_pkg_by_pattern(xbps_dictionary_t repod, const char *p)
}
}
free(pkgname);
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))) {
xbps_string_t rpkg;
char *dpkgname, *vpkgname;
char buf[XBPS_NAME_SIZE];
char *vpkgname;
const char *vpkg_conf;
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);
if (xbps_pkg_version(vpkg_conf)) {
vpkgname = xbps_pkg_name(vpkg_conf);
assert(vpkgname);
if (!xbps_pkg_name(buf, XBPS_NAME_SIZE, vpkg_conf)) {
abort();
}
vpkgname = strdup(buf);
} else {
vpkgname = strdup(vpkg_conf);
assert(vpkgname);
}
assert(vpkgname);
if (xbps_pkgpattern_version(vpkg)) {
char *vpkgver;
@ -246,14 +245,13 @@ vpkg_user_conf(struct xbps_handle *xhp, const char *vpkg, bool only_conf)
free(vpkgver);
}
} else if (xbps_pkg_version(vpkg)) {
dpkgname = xbps_pkg_name(vpkg);
assert(dpkgname);
if (strcmp(dpkgname, vpkgname)) {
free(dpkgname);
if (!xbps_pkg_name(buf, XBPS_NAME_SIZE, vpkg)) {
abort();
}
if (strcmp(buf, vpkgname)) {
free(vpkgname);
continue;
}
free(dpkgname);
} else {
if (strcmp(vpkg, 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_t obj;
const char *pkgdep;
char *curpkgname;
char pkgname[XBPS_NAME_SIZE];
bool found = false;
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) {
/* match by pkgname against pkgver */
pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(pkgdep);
if (curpkgname == NULL)
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgdep))
break;
if (strcmp(curpkgname, str) == 0) {
free(curpkgname);
if (strcmp(pkgname, str) == 0) {
found = true;
break;
}
free(curpkgname);
} else if (mode == 2) {
/* match by pkgver against pkgname */
pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(str);
if (curpkgname == NULL)
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, str))
break;
if (strcmp(curpkgname, pkgdep) == 0) {
free(curpkgname);
if (strcmp(pkgname, pkgdep) == 0) {
found = true;
break;
}
free(curpkgname);
} else if (mode == 3) {
/* match pkgpattern against pkgdep */
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_t obj;
const char *curname, *pkgdep;
char *curpkgname;
char curpkgname[XBPS_NAME_SIZE];
unsigned int idx = 0;
bool found = false;
@ -57,15 +57,13 @@ remove_obj_from_array(xbps_array_t array, const char *str, int mode)
} else if (mode == 1) {
/* match by pkgname, obj is a string */
pkgdep = xbps_string_cstring_nocopy(obj);
curpkgname = xbps_pkg_name(pkgdep);
if (curpkgname == NULL)
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgdep))
break;
if (strcmp(curpkgname, str) == 0) {
free(curpkgname);
found = true;
break;
}
free(curpkgname);
} else if (mode == 2) {
/* match by pkgname, obj is a dictionary */
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"))) {
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);
vpkgn = xbps_pkg_name(vpkg);
assert(vpkgn);
if (!xbps_pkg_name(vpkgn, XBPS_NAME_SIZE, vpkg)) {
abort();
}
if (strcmp(vpkgn, pkg) == 0) {
free(vpkgn);
match = true;
break;
}
free(vpkgn);
vpkg = NULL;
}
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) {
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);
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);
if (curver == NULL || pkgver == NULL)
goto out;
curpkgnamedep = xbps_pkgpattern_name(curdep);
if (curpkgnamedep == NULL)
if (!xbps_pkgpattern_name(curpkgnamedep, XBPS_NAME_SIZE, curdep)) {
goto out;
pkgnamedep = xbps_pkgpattern_name(reqpkg);
if (pkgnamedep == NULL) {
free(curpkgnamedep);
}
if (!xbps_pkgpattern_name(pkgnamedep, XBPS_NAME_SIZE, reqpkg)) {
goto out;
}
if (strcmp(pkgnamedep, curpkgnamedep) == 0) {
pkgfound = true;
if (strcmp(curver, pkgver) == 0) {
free(curpkgnamedep);
free(pkgnamedep);
rv = EEXIST;
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);
if (xbps_cmpver(curver, pkgver) <= 0) {
add_pkgdep = false;
free(curpkgnamedep);
free(pkgnamedep);
rv = EEXIST;
goto out;
}
update_pkgdep = true;
}
free(curpkgnamedep);
free(pkgnamedep);
if (pkgfound)
break;
@ -123,13 +116,8 @@ find_repo_deps(struct xbps_handle *xhp,
const char *curpkg, /* current pkgver */
unsigned short *depth) /* max recursion depth */
{
xbps_dictionary_t curpkgd = NULL;
xbps_object_t obj;
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;
if (*depth >= MAX_DEPTH)
@ -143,7 +131,13 @@ find_repo_deps(struct xbps_handle *xhp,
assert(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;
reqpkg = xbps_string_cstring_nocopy(obj);
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);
}
if (((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) &&
((pkgname = xbps_pkg_name(reqpkg)) == NULL)) {
if ((!xbps_pkgpattern_name(pkgname, sizeof(pkgname), reqpkg)) &&
(!xbps_pkg_name(pkgname, sizeof(pkgname), 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,
"%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)) {
xbps_dbg_printf_append(xhp, "%s ignored.\n", pkgname);
free(pkgname);
continue;
}
/*
@ -175,7 +168,6 @@ find_repo_deps(struct xbps_handle *xhp,
*/
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);
free(pkgname);
continue;
}
/*
@ -186,7 +178,6 @@ find_repo_deps(struct xbps_handle *xhp,
(curpkgd = xbps_find_virtualpkg_in_array(xhp, unsorted, reqpkg, NULL))) {
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
xbps_dbg_printf_append(xhp, " (%s queued)\n", pkgver_q);
free(pkgname);
continue;
}
/*
@ -208,15 +199,14 @@ find_repo_deps(struct xbps_handle *xhp,
curpkgd = NULL;
}
if (curpkgd == NULL) {
if (errno && errno != ENOENT) {
/* error */
rv = errno;
xbps_dbg_printf(xhp, "failed to find installed pkg for `%s': %s\n", reqpkg, strerror(rv));
free(pkgname);
break;
}
free(pkgname);
/* Required dependency not installed */
xbps_dbg_printf_append(xhp, "not installed.\n");
reason = "install";
@ -230,7 +220,6 @@ find_repo_deps(struct xbps_handle *xhp,
/* Check its state */
if ((rv = xbps_pkg_state_dictionary(curpkgd, &state)) != 0) {
free(pkgname);
break;
}
@ -240,17 +229,18 @@ find_repo_deps(struct xbps_handle *xhp,
* by an installed package.
*/
xbps_dbg_printf_append(xhp, "[virtual] satisfied by `%s'.\n", pkgver_q);
free(pkgname);
continue;
}
rv = xbps_pkgpattern_match(pkgver_q, reqpkg);
if (rv == 0) {
char *curpkgname;
char curpkgname[XBPS_NAME_SIZE];
/*
* The version requirement is not satisfied.
*/
curpkgname = xbps_pkg_name(pkgver_q);
assert(curpkgname);
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver_q)) {
abort();
}
if (strcmp(pkgname, curpkgname)) {
xbps_dbg_printf_append(xhp, "not installed `%s (vpkg)'", pkgver_q);
if (xbps_dictionary_get(curpkgd, "hold")) {
@ -268,13 +258,10 @@ find_repo_deps(struct xbps_handle *xhp,
reason = "update";
}
}
free(curpkgname);
free(pkgname);
} else if (rv == 1) {
/*
* The version requirement is satisfied.
*/
free(pkgname);
rv = 0;
if (state == XBPS_PKG_STATE_UNPACKED) {
/*
@ -294,7 +281,6 @@ find_repo_deps(struct xbps_handle *xhp,
} else {
/* error matching pkgpattern */
xbps_dbg_printf(xhp, "failed to match pattern %s with %s\n", reqpkg, pkgver_q);
free(pkgname);
break;
}
}
@ -328,23 +314,25 @@ find_repo_deps(struct xbps_handle *xhp,
continue;
}
}
xbps_dictionary_get_cstring_nocopy(curpkgd, "pkgver", &pkgver_q);
reqpkgname = xbps_pkg_name(pkgver_q);
assert(reqpkgname);
if (!xbps_pkg_name(reqpkgname, sizeof(reqpkgname), pkgver_q)) {
rv = EINVAL;
break;
}
/*
* Check dependency validity.
*/
pkgname = xbps_pkg_name(curpkg);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), curpkg)) {
rv = EINVAL;
break;
}
if (strcmp(pkgname, reqpkgname) == 0) {
xbps_dbg_printf_append(xhp, "[ignoring wrong dependency %s (depends on itself)]\n", reqpkg);
xbps_remove_string_from_array(pkg_rdeps_array, reqpkg);
free(pkgname);
free(reqpkgname);
continue;
}
free(pkgname);
free(reqpkgname);
/*
* Installed package must be updated, check if dependency is
* satisfied.
@ -354,8 +342,9 @@ find_repo_deps(struct xbps_handle *xhp,
case 0: /* nomatch */
break;
case 1: /* match */
pkgname = xbps_pkg_name(pkgver_q);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver_q)) {
abort();
}
/*
* If there's an update in transaction,
* it's assumed version is greater.
@ -366,7 +355,6 @@ find_repo_deps(struct xbps_handle *xhp,
error = true;
rv = ENODEV;
}
free(pkgname);
break;
default:
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_iterator_t iter;
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");
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");
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);
assert(iter);
@ -75,10 +79,10 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
/* Ignore itself */
xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
if (strcmp(pkgname, repopkgname) == 0) {
free(pkgname);
continue;
}
/*
@ -92,11 +96,9 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
!strcmp(tract, "update") ||
!strcmp(tract, "remove") ||
!strcmp(tract, "hold")) {
free(pkgname);
continue;
}
}
free(pkgname);
xbps_dbg_printf(xhp, "found conflicting installed "
"pkg %s with pkg in transaction %s "
"(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 */
xbps_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
if (strcmp(pkgname, repopkgname) == 0) {
free(pkgname);
continue;
}
free(pkgname);
xbps_dbg_printf(xhp, "found conflicting pkgs in "
"transaction %s <-> %s (matched by %s [trans])\n",
pkgver, repopkgver, cfpkg);
@ -144,7 +145,6 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array,
}
}
xbps_object_iterator_release(iter);
free(repopkgname);
}
static int
@ -156,7 +156,9 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
xbps_object_t obj2;
xbps_object_iterator_t iter;
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");
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");
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &repopkgver);
repopkgname = xbps_pkg_name(repopkgver);
assert(repopkgname);
if (!xbps_pkg_name(repopkgname, XBPS_NAME_SIZE, repopkgver)) {
abort();
}
/* if a pkg is in the transaction, ignore the one from pkgdb */
if (xbps_find_pkg_in_array(pkgs, repopkgname, NULL)) {
free(repopkgname);
return 0;
}
@ -189,13 +191,12 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
continue;
}
/* ignore itself */
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
if (strcmp(pkgname, repopkgname) == 0) {
free(pkgname);
continue;
}
free(pkgname);
xbps_dbg_printf(xhp, "found conflicting pkgs in "
"transaction %s <-> %s (matched by %s [pkgdb])\n",
pkgver, repopkgver, cfpkg);
@ -210,7 +211,6 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj,
}
}
xbps_object_iterator_release(iter);
free(repopkgname);
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 stat st;
const char *pkgver;
char *bpkg, *pkgname;
char *bpkg, pkgname[XBPS_NAME_SIZE];
/* size_t entry_size; */
int rv = 0, pkg_fd = -1;
xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
assert(pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
bpkg = xbps_repository_pkg_path(xhp, pkg_repod);
if (bpkg == NULL) {
@ -750,7 +751,6 @@ out:
if (ar)
archive_read_finish(ar);
free(bpkg);
free(pkgname);
return rv;
}
@ -768,7 +768,7 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
xbps_dictionary_t pkgd, filesd;
xbps_object_t obj;
const char *trans, *pkgver;
char *pkgname = NULL;
char pkgname[XBPS_NAME_SIZE];
int rv = 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);
assert(pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
update = strcmp(trans, "update") == 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);
if (filesd == NULL) {
free(pkgname);
pkgname = NULL;
continue;
}
@ -841,8 +839,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
if (rv != 0)
goto out;
}
free(pkgname);
pkgname = NULL;
}
xbps_object_iterator_reset(iter);
@ -860,7 +856,6 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
}
out:
free(pkgname);
if (rv != 0)
return rv;
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_array_t pkgs;
const char *repoloc, *repopkgver, *instpkgver, *reason;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
int action = 0, rv = 0;
pkg_state_t state = 0;
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.
*/
if ((pkgname = xbps_pkg_name(pkg))) {
if (xbps_pkg_name(pkgname, sizeof(pkgname), pkg)) {
pkg_pkgdb = xbps_pkgdb_get_pkg(xhp, pkgname);
free(pkgname);
} else {
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);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), repopkgver)) {
abort();
}
/*
* Set package state in dictionary with same state than the
* package currently uses, otherwise not-installed.
*/
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
if (rv != ENOENT) {
free(pkgname);
return rv;
}
/* Package not installed, don't error out */
state = XBPS_PKG_STATE_NOT_INSTALLED;
}
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) {
free(pkgname);
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,
"transaction", reason)) {
free(pkgname);
return EINVAL;
}
if ((rv = xbps_transaction_store(xhp, pkgs, pkg_repod, reason, false)) != 0) {
free(pkgname);
return rv;
}
free(pkgname);
return 0;
return xbps_transaction_store(xhp, pkgs, pkg_repod, reason, false);
}
/*
@ -238,7 +231,7 @@ xbps_autoupdate(struct xbps_handle *xhp)
xbps_array_t rdeps;
xbps_dictionary_t pkgd;
const char *pkgver;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
int rv;
/*
@ -250,11 +243,11 @@ xbps_autoupdate(struct xbps_handle *xhp)
return 0;
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);
free(pkgname);
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");
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
const char *curpkgver = NULL;
char *curpkgn;
char curpkgn[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
xbps_dbg_printf(xhp, "%s: processing revdep %s\n", __func__, curpkgver);
curpkgn = xbps_pkg_name(curpkgver);
assert(curpkgn);
if (!xbps_pkg_name(curpkgn, sizeof(curpkgn), curpkgver)) {
abort();
}
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);
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
return -1;
@ -305,12 +298,9 @@ xbps_autoupdate(struct xbps_handle *xhp)
int
xbps_transaction_update_packages(struct xbps_handle *xhp)
{
xbps_dictionary_t pkgd;
xbps_object_t obj;
xbps_object_iterator_t iter;
const char *pkgver;
char *pkgname;
bool hold, newpkg_found = false;
bool newpkg_found = false;
int rv = 0;
rv = xbps_autoupdate(xhp);
@ -329,7 +319,11 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
assert(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);
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver))
continue;
@ -338,8 +332,9 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
xbps_dbg_printf(xhp, "[rpool] package `%s' "
"on hold, ignoring updates.\n", pkgver);
}
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
rv = trans_find_pkg(xhp, pkgname, false, hold);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
if (rv == 0) {
@ -351,7 +346,6 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
*/
rv = 0;
}
free(pkgname);
}
xbps_object_iterator_release(iter);
@ -385,15 +379,15 @@ xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg)
rdeps = NULL;
}
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
const char *curpkgver = NULL;
char *curpkgn;
const char *pkgver = NULL;
char pkgname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
curpkgn = xbps_pkg_name(curpkgver);
assert(curpkgn);
rv = trans_find_pkg(xhp, curpkgn, false, false);
free(curpkgn);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, curpkgver, rv);
xbps_array_get_cstring_nocopy(rdeps, i, &pkgver);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
rv = trans_find_pkg(xhp, pkgname, false, false);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
return rv;
}
@ -429,15 +423,15 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg,
rdeps = NULL;
}
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
const char *curpkgver = NULL;
char *curpkgn;
const char *pkgver = NULL;
char pkgname[XBPS_NAME_SIZE];
xbps_array_get_cstring_nocopy(rdeps, i, &curpkgver);
curpkgn = xbps_pkg_name(curpkgver);
assert(curpkgn);
rv = trans_find_pkg(xhp, curpkgn, false, false);
free(curpkgn);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, curpkgver, rv);
xbps_array_get_cstring_nocopy(rdeps, i, &pkgver);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
rv = trans_find_pkg(xhp, pkgname, false, false);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV)
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_iterator_t iter;
const char *pkgver;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
obj = xbps_array_get(pkgs, i);
replaces = xbps_dictionary_get(obj, "replaces");
@ -52,13 +52,14 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
assert(iter);
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
while ((obj2 = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_t instd, reppkgd;
const char *pattern = NULL, *curpkgver = NULL;
char *curpkgname;
char curpkgname[XBPS_NAME_SIZE];
bool instd_auto = false, hold = false;
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)
continue;
curpkgname = xbps_pkg_name(curpkgver);
assert(curpkgname);
if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) {
abort();
}
/*
* Check that we are not replacing the same package,
* due to virtual packages.
*/
if (strcmp(pkgname, curpkgname) == 0) {
free(curpkgname);
continue;
}
/*
@ -143,14 +144,10 @@ xbps_transaction_package_replace(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_dictionary_set_bool(instd, "replaced", true);
if (!xbps_array_add_first(pkgs, instd)) {
xbps_object_iterator_release(iter);
free(pkgname);
free(curpkgname);
return EINVAL;
}
free(curpkgname);
}
xbps_object_iterator_release(iter);
free(pkgname);
}
return 0;

View File

@ -131,12 +131,12 @@ compute_transaction_stats(struct xbps_handle *xhp)
*/
if ((strcmp(tract, "remove") == 0) ||
((strcmp(tract, "update") == 0) && !preserve)) {
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
pkg_metad = xbps_pkgdb_get_pkg(xhp, pkgname);
free(pkgname);
if (pkg_metad == NULL)
continue;
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++) {
xbps_array_t rundeps;
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;
pkgname = vpkgname = vpkgver = str = NULL;
xbps_dictionary_get_cstring_nocopy(trans_pkgd, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(rev_pkgd, "pkgver", &revpkgver);
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");
for (unsigned int x = 0; x < xbps_array_count(rundeps); x++) {
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;
if (strcmp(vpkgname, pkgname)) {
free(pkgname);
continue;
}
free(pkgname);
if (!strcmp(vpkgver, pkgpattern) ||
xbps_pkgpattern_match(vpkgver, pkgpattern)) {
continue;
@ -85,7 +87,6 @@ check_virtual_pkgs(xbps_array_t mdeps,
free(str);
matched = true;
}
free(vpkgname);
free(vpkgver);
}
return matched;
@ -112,7 +113,7 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_array_t pkgrdeps;
xbps_object_t obj;
const char *pkgver, *tract;
char *pkgname;
char pkgname[XBPS_NAME_SIZE];
obj = xbps_array_get(pkgs, i);
/*
@ -129,10 +130,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
continue;
}
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
if (xbps_pkg_is_installed(xhp, pkgname) == 0) {
free(pkgname);
continue;
}
/*
@ -141,13 +143,11 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
*/
pkgrdeps = xbps_pkgdb_get_pkg_revdeps(xhp, pkgname);
if (!xbps_array_count(pkgrdeps)) {
free(pkgname);
continue;
}
/*
* If pkg is ignored, pass to the next one.
*/
free(pkgname);
if (xbps_pkg_is_ignored(xhp, pkgver)) {
continue;
}
@ -159,12 +159,15 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
xbps_array_t rundeps;
xbps_dictionary_t revpkgd;
const char *curpkgver = NULL, *revpkgver, *curdep = NULL, *curtract;
char *curpkgname, *curdepname;
char curpkgname[XBPS_NAME_SIZE];
char curdepname[XBPS_NAME_SIZE];
bool found = false;
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))) {
xbps_dictionary_get_cstring_nocopy(revpkgd, "transaction", &curtract);
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 (xbps_dictionary_get(obj, "replaced")) {
free(pkgname);
continue;
}
if (xbps_find_pkg_in_array(pkgs, pkgname, "remove")) {
free(pkgname);
continue;
}
free(pkgname);
broken_pkg(mdeps, curpkgver, pkgver, tract);
continue;
}
@ -196,7 +196,6 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
* First try to match any supported virtual package.
*/
if (check_virtual_pkgs(mdeps, obj, revpkgd)) {
free(pkgname);
continue;
}
/*
@ -206,30 +205,26 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
/*
* Find out what dependency is it.
*/
curpkgname = xbps_pkg_name(pkgver);
assert(curpkgname);
if (!xbps_pkg_name(curpkgname, sizeof(curpkgname), pkgver)) {
abort();
}
for (unsigned int j = 0; j < xbps_array_count(rundeps); j++) {
xbps_array_get_cstring_nocopy(rundeps, j, &curdep);
if (((curdepname = xbps_pkg_name(curdep)) == NULL) &&
((curdepname = xbps_pkgpattern_name(curdep)) == NULL))
if ((!xbps_pkgpattern_name(curdepname, sizeof(curdepname), curdep)) &&
(!xbps_pkg_name(curdepname, sizeof(curdepname), curdep))) {
abort();
}
if (strcmp(curdepname, curpkgname) == 0) {
free(curdepname);
found = true;
break;
}
free(curdepname);
}
free(curpkgname);
if (!found) {
free(pkgname);
continue;
}
if (xbps_match_pkgdep_in_array(rundeps, pkgver)) {
free(pkgname);
continue;
}
/*
@ -239,10 +234,8 @@ xbps_transaction_revdeps(struct xbps_handle *xhp, xbps_array_t pkgs)
* is in the transaction.
*/
if (xbps_find_pkg_in_array(pkgs, pkgname, "update")) {
free(pkgname);
continue;
}
free(pkgname);
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);
while ((obj = xbps_object_iterator_next(iter))) {
const char *trans = NULL;
char *pkgname = NULL;
char pkgname[XBPS_NAME_SIZE];
if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver))
continue;
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) {
abort();
}
/* ignore shlibs if pkg is on hold mode */
if (xbps_dictionary_get_cstring_nocopy(obj, "transaction", &trans)) {
if (!strcmp(trans, "hold")) {
free(pkgname);
continue;
}
}
xbps_dictionary_set(pd, pkgname, obj);
free(pkgname);
}
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;
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, "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)
replaces = xbps_array_create();
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
abort();
}
self_replaced = xbps_xasprintf("%s>=0", pkgname);
free(pkgname);
xbps_array_add_cstring(replaces, self_replaced);
free(self_replaced);

View File

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

View File

@ -36,49 +36,61 @@ ATF_TC_HEAD(util_test, tc)
ATF_TC_BODY(util_test, tc)
{
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-a"), NULL);
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("font-adobe-100dpi-7.8"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("python-e_dbus"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v1"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("fs-utils-v_1"), NULL);
ATF_CHECK_EQ(xbps_pkg_name("font-adobe-100dpi-1.8_blah"), NULL);
char name[XBPS_NAME_SIZE];
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-a"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-1"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-100dpi"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-100dpi-7.8"), false);
ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "python-e_dbus"), false);
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("font-adobe-100dpi"), 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-1"), 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("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("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_revision("systemd_21-43_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_pkgpattern_name("systemd>=43"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>43"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<43"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<=43"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd-[0-9]*"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd>4[3-9]?"), "systemd");
ATF_REQUIRE_STREQ(xbps_pkgpattern_name("systemd<4_1?"), "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>43"), true);
ATF_REQUIRE_STREQ(name, "systemd");
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<=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-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_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("/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_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64.xbps"), NULL);
ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64"), NULL);
}