Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix memory corruption when using pkg files.
Vsevolod Stakhov committed 11 years ago
commit 5b754c26e4b3e3bfa79535e122d2314828f89f19
parent 2da00db
6 files changed +19 -12
modified libpkg/pkg.h.in
@@ -1340,7 +1340,7 @@ int pkg_fetch_file_tmp(struct pkg_repo *repo, const char *url, char *dest,
/**
 * Get cached name of a package
 */
-
void pkg_repo_cached_name(struct pkg *pkg, char *dest, size_t destlen);
+
int pkg_repo_cached_name(struct pkg *pkg, char *dest, size_t destlen);

/* glue to deal with ports */
int ports_parse_plist(struct pkg *, const char *, const char *);
modified libpkg/pkg_repo.c
@@ -1114,17 +1114,17 @@ pkg_repo_mirror_package(struct pkg *pkg, const char *destdir)
	return (repo->ops->mirror_pkg(repo, pkg, destdir));
}

-
void
+
int
pkg_repo_cached_name(struct pkg *pkg, char *dest, size_t destlen)
{
	struct pkg_repo *repo;

	if (pkg->repo == NULL)
-
		return;
+
		return (EPKG_FATAL);

	repo = pkg->repo;
	if (repo->ops->get_cached_name == NULL)
-
		return;
+
		return (EPKG_FATAL);

-
	repo->ops->get_cached_name(repo, pkg, dest, destlen);
+
	return (repo->ops->get_cached_name(repo, pkg, dest, destlen));
}
modified libpkg/private/pkg.h
@@ -384,7 +384,7 @@ struct pkg_repo_ops {
	int (*ensure_loaded)(struct pkg_repo *repo, struct pkg *pkg, unsigned flags);

	/* Fetch package from repo */
-
	void (*get_cached_name)(struct pkg_repo *, struct pkg *,
+
	int (*get_cached_name)(struct pkg_repo *, struct pkg *,
					char *dest, size_t destlen);
	int (*fetch_pkg)(struct pkg_repo *, struct pkg *);
	int (*mirror_pkg)(struct pkg_repo *repo, struct pkg *pkg,
modified libpkg/repo/binary/binary.h
@@ -53,7 +53,7 @@ int pkg_repo_binary_ensure_loaded(struct pkg_repo *repo,
int64_t pkg_repo_binary_stat(struct pkg_repo *repo, pkg_stats_t type);

int pkg_repo_binary_fetch(struct pkg_repo *repo, struct pkg *pkg);
-
void pkg_repo_binary_get_cached_name(struct pkg_repo *repo, struct pkg *pkg,
+
int pkg_repo_binary_get_cached_name(struct pkg_repo *repo, struct pkg *pkg,
	char *dest, size_t destlen);
int pkg_repo_binary_mirror(struct pkg_repo *repo, struct pkg *pkg,
	const char *destdir);
modified libpkg/repo/binary/fetch.c
@@ -50,7 +50,7 @@
#include "private/pkg.h"
#include "binary.h"

-
void
+
int
pkg_repo_binary_get_cached_name(struct pkg_repo *repo, struct pkg *pkg,
	char *dest, size_t destlen)
{
@@ -75,7 +75,7 @@ pkg_repo_binary_get_cached_name(struct pkg_repo *repo, struct pkg *pkg,
		pkg_snprintf(dest, destlen, "%S/%n-%v-%z",
				cachedir, pkg, pkg, pkg);
		if (stat (dest, &st) != -1)
-
			return;
+
			return (EPKG_FATAL);

		/*
		 * The real naming scheme:
@@ -88,6 +88,8 @@ pkg_repo_binary_get_cached_name(struct pkg_repo *repo, struct pkg *pkg,
		pkg_snprintf(dest, destlen, "%S/%n-%v-%z",
				cachedir, pkg, pkg, pkg);
	}
+

+
	return (EPKG_OK);
}

static int
modified src/utils.c
@@ -665,6 +665,7 @@ set_jobs_summary_pkg(struct pkg_jobs *jobs,
{
	const char *oldversion, *repopath, *destdir;
	char path[MAXPATHLEN];
+
	int ret;
	struct stat st;
	int64_t flatsize, oldflatsize, pkgsize;
	struct pkg_solved_display_item *it;
@@ -698,12 +699,16 @@ set_jobs_summary_pkg(struct pkg_jobs *jobs,
	switch (type) {
	case PKG_SOLVED_INSTALL:
	case PKG_SOLVED_UPGRADE:
+
		ret = EPKG_FATAL;
+

		if (destdir == NULL)
-
			pkg_repo_cached_name(new_pkg, path, sizeof(path));
-
		else
+
			ret = pkg_repo_cached_name(new_pkg, path, sizeof(path));
+
		else if (repopath != NULL) {
			snprintf(path, sizeof(path), "%s/%s", destdir, repopath);
+
			ret = EPKG_OK;
+
		}

-
		if (stat(path, &st) == -1 || pkgsize != st.st_size)
+
		if (ret == EPKG_OK && (stat(path, &st) == -1 || pkgsize != st.st_size))
			/* file looks corrupted (wrong size),
					   assume a checksum mismatch will
					   occur later and the file will be