Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix a dirname(3) race
Baptiste Daroussin committed 10 years ago
commit 5eab35db18889d0c5b5ca8e427aa5811ce9de1fa
parent 5ac8743
1 file changed +4 -3
modified libpkg/pkg_add.c
@@ -659,7 +659,8 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,
	fromstdin = (strcmp(path, "-") == 0);
	strlcpy(bd, path, sizeof(bd));
	if (!fromstdin) {
-
		basedir = dirname(bd);
+
		basedir = bsd_dirname(bd);
+
		strlcpy(bd, basedir, sizeof(bd));
		if ((ext = strrchr(path, '.')) == NULL) {
			pkg_emit_error("%s has no extension", path);
			return (EPKG_FATAL);
@@ -681,7 +682,7 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,
		}

		if (dep->version != NULL && dep->version[0] != '\0') {
-
			snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", basedir,
+
			snprintf(dpath, sizeof(dpath), "%s/%s-%s%s", bd,
				dep->name, dep->version, ext);

			if ((flags & PKG_ADD_UPGRADE) == 0 &&
@@ -697,7 +698,7 @@ pkg_add_check_pkg_archive(struct pkgdb *db, struct pkg *pkg,
					goto cleanup;
			}
		} else {
-
			snprintf(dpath, sizeof(dpath), "%s/%s-*%s", basedir,
+
			snprintf(dpath, sizeof(dpath), "%s/%s-*%s", bd,
			    dep->name, ext);
			ppath = pkg_globmatch(dpath, dep->name);
			if (ppath == NULL) {