Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg_add: replace stringlist with c_charv_t
Baptiste Daroussin committed 1 year ago
commit 6485306ee568a44b31d254f2b7fa6d5bdf71c486
parent 513e1b1
3 files changed +23 -21
modified libpkg/pkg_add.c
@@ -421,7 +421,7 @@ reopen_tempdir(int rootfd, struct tempdir *t)
}

static struct tempdir *
-
get_tempdir(int rootfd, const char *path, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
get_tempdir(int rootfd, const char *path, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct tempdir *tmpdir = NULL;

@@ -451,7 +451,7 @@ close_tempdir(struct tempdir *t)
}

static int
-
create_dir(struct pkg *pkg, struct pkg_dir *d, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
create_dir(struct pkg *pkg, struct pkg_dir *d, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct stat st;
	struct tempdir *tmpdir = NULL;
@@ -501,7 +501,7 @@ create_dir(struct pkg *pkg, struct pkg_dir *d, tempdirs_t *tempdirs, stringlist_
/* In case of directories create the dir and extract the creds */
static int
do_extract_dir(struct pkg* pkg, struct archive *a __unused, struct archive_entry *ae,
-
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct pkg_dir *d;
	const struct stat *aest;
@@ -547,7 +547,7 @@ try_mkdir(int fd, const char *path)

static int
create_symlinks(struct pkg *pkg, struct pkg_file *f, const char *target, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	struct tempdir *tmpdir = NULL;
	int fd;
@@ -594,7 +594,7 @@ retry:
static int
do_extract_symlink(struct pkg *pkg, struct archive *a __unused, struct archive_entry *ae,
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	struct pkg_file *f;
	const struct stat *aest;
@@ -626,7 +626,7 @@ do_extract_symlink(struct pkg *pkg, struct archive *a __unused, struct archive_e

static int
create_hardlink(struct pkg *pkg, struct pkg_file *f, const char *path, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	bool tried_mkdir = false;
	struct pkg_file *fh;
@@ -702,7 +702,7 @@ retry:
static int
do_extract_hardlink(struct pkg *pkg, struct archive *a __unused, struct archive_entry *ae,
    const char *path, struct pkg *local __unused, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	struct pkg_file *f;
	const struct stat *aest;
@@ -749,7 +749,7 @@ retry:
static int
create_regfile(struct pkg *pkg, struct pkg_file *f, struct archive *a,
    struct archive_entry *ae, int fromfd, struct pkg *local, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	int fd = -1;
	size_t len;
@@ -842,7 +842,7 @@ create_regfile(struct pkg *pkg, struct pkg_file *f, struct archive *a,

static int
do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,
-
    const char *path, struct pkg *local, tempdirs_t *tempdirs, stringlist_t *symlinks_allowed)
+
    const char *path, struct pkg *local, tempdirs_t *tempdirs, c_charv_t *symlinks_allowed)
{
	struct pkg_file *f;
	const struct stat *aest;
@@ -875,14 +875,14 @@ do_extract_regfile(struct pkg *pkg, struct archive *a, struct archive_entry *ae,
static int
do_extract(struct archive *a, struct archive_entry *ae,
    int nfiles, struct pkg *pkg, struct pkg *local, tempdirs_t *tempdirs,
-
    stringlist_t *symlinks_allowed)
+
    c_charv_t *symlinks_allowed)
{
	int	retcode = EPKG_OK;
	int	ret = 0, cur_file = 0;
	char	path[MAXPATHLEN];
	int (*extract_cb)(struct pkg *pkg, struct archive *a,
	    struct archive_entry *ae, const char *path, struct pkg *local,
-
	    tempdirs_t *tempdirs, stringlist_t *sa);
+
	    tempdirs_t *tempdirs, c_charv_t *sa);

#ifndef HAVE_ARC4RANDOM
	srand(time(NULL));
@@ -1357,11 +1357,12 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	int			 ret;
	int			 nfiles;
	tempdirs_t		 tempdirs;
-
	stringlist_t		 symlinks_allowed = tll_init();
+
	c_charv_t		 symlinks_allowed;

	assert(path != NULL);

	pkgvec_init(&tempdirs);
+
	pkgvec_init(&symlinks_allowed);

	/*
	 * Open the package archive file, read all the meta files and set the
@@ -1464,7 +1465,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	 */
	if (extract) {
		pkg_register_cleanup_callback(pkg_rollback_cb, pkg);
-
		tll_push_back(symlinks_allowed, pkg->prefix);
+
		pkgvec_push(&symlinks_allowed, pkg->prefix);
		retcode = do_extract(a, ae, nfiles, pkg, local, &tempdirs, &symlinks_allowed);
		pkg_unregister_cleanup_callback(pkg_rollback_cb, pkg);
		if (retcode != EPKG_OK) {
@@ -1563,7 +1564,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
	}

cleanup:
-
	tll_free(symlinks_allowed);
+
	pkgvec_free(&symlinks_allowed);

	if (openxact)
		pkgdb_register_finale(db, retcode, NULL);
@@ -1662,9 +1663,10 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
	size_t link_len;
	bool install_as_user;
	tempdirs_t tempdirs;
-
	stringlist_t symlinks_allowed = tll_init();
-
	tll_push_back(symlinks_allowed, pkg->prefix);
+
	c_charv_t symlinks_allowed;

+
	pkgvec_init(&symlinks_allowed);
+
	pkgvec_push(&symlinks_allowed, pkg->prefix);
	pkgvec_init(&hardlinks);
	pkgvec_init(&tempdirs);
	install_as_user = (getenv("INSTALL_AS_USER") != NULL);
@@ -1843,7 +1845,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
	retcode = pkg_extract_finalize(pkg, &tempdirs);

cleanup:
-
	tll_free(symlinks_allowed);
+
	pkgvec_free(&symlinks_allowed);
	pkgvec_free_and_free(&hardlinks, free);
	close(fromfd);
	return (retcode);
modified libpkg/private/utils.h
@@ -116,7 +116,7 @@ char *rtrimspace(char *buf);
void hidden_tempfile(char *buf, int buflen, const char *path);
void append_random_suffix(char *buf, int buflen, int suffixlen);
char *json_escape(const char *str);
-
struct tempdir *open_tempdir(int rootfd, const char *path, stringlist_t *strlist);
+
struct tempdir *open_tempdir(int rootfd, const char *path, c_charv_t *strlist);
const char *get_http_auth(void);
bool c_charv_contains(c_charv_t *, const char *, bool);

modified libpkg/utils.c
@@ -984,7 +984,7 @@ json_escape(const char *str)
}

struct tempdir *
-
open_tempdir(int rootfd, const char *path, stringlist_t *symlinks_allowed)
+
open_tempdir(int rootfd, const char *path, c_charv_t *symlinks_allowed)
{
	struct stat st;
	char walk[MAXPATHLEN];
@@ -1003,8 +1003,8 @@ open_tempdir(int rootfd, const char *path, stringlist_t *symlinks_allowed)
		if (len > 0) {
			int flag = AT_SYMLINK_NOFOLLOW;
			if (symlinks_allowed != NULL) {
-
				tll_foreach(*symlinks_allowed, t) {
-
					if (STREQ(RELATIVE_PATH(walk), RELATIVE_PATH(t->item)))
+
				for (size_t i = 0; i < symlinks_allowed->len; i++) {
+
					if (STREQ(RELATIVE_PATH(walk), RELATIVE_PATH(symlinks_allowed->d[i])))
						flag = 0;
				}
			}