Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg_fetch_file now takes a mkstemp(3) pattern
Baptiste Daroussin committed 12 years ago
commit e46bf03292cd5c2ef50907bf7ef827093ca87c00
parent dfff2c3
3 files changed +17 -10
modified libpkg/fetch.c
@@ -82,13 +82,17 @@ gethttpmirrors(struct pkg_repo *repo, const char *url) {
}

int
-
pkg_fetch_file(struct pkg_repo *repo, const char *url, const char *dest, time_t t)
+
pkg_fetch_file(struct pkg_repo *repo, const char *url, char *dest, time_t t)
{
	int fd = -1;
	int retcode = EPKG_FATAL;
+
	mode_t mask;

-
	if ((fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644)) == -1) {
-
		pkg_emit_errno("open", dest);
+
	mask = umask(022);
+
	fd = mkstemp(dest);
+
	umask(mask);
+
	if (fd == -1) {
+
		pkg_emit_errno("mkstemp", dest);
		return(EPKG_FATAL);
	}

@@ -530,8 +534,10 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t
	}

	now = begin_dl = time(NULL);
-
	repo->tofetch = sz;
-
	repo->fetched = 0;
+
	if (repo != NULL) {
+
		repo->tofetch = sz;
+
		repo->fetched = 0;
+
	}
	while (done < sz) {
		if ((r = fread(buf, 1, sizeof(buf), remote)) < 1)
			break;
@@ -550,7 +556,8 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t
			last = now;
		}
	}
-
	repo->tofetch = 0;
+
	if (repo != NULL)
+
		repo->tofetch = 0;

	if (done < sz) {
		pkg_emit_error("An error occurred while fetching package");
@@ -567,7 +574,7 @@ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t
	cleanup:

	if (u != NULL) {
-
		if (remote != NULL && remote != repo->ssh)
+
		if (remote != NULL &&  repo != NULL && remote != repo->ssh)
			fclose(remote);
	}

modified libpkg/pkg.h.in
@@ -1235,7 +1235,7 @@ pkg_change_t pkg_version_change(const struct pkg * restrict);
 * Fetch a file.
 * @return An error code.
 */
-
int pkg_fetch_file(struct pkg_repo *repo, const char *url, const char *dest, time_t t);
+
int pkg_fetch_file(struct pkg_repo *repo, const char *url, char *dest, time_t t);

/* glue to deal with ports */
int ports_parse_plist(struct pkg *, const char *, const char *);
modified pkg/audit.c
@@ -150,9 +150,9 @@ fetch_and_extract(const char *src, const char *dest, bool xml)
		tmpdir = "/tmp";
	strlcpy(tmp, tmpdir, sizeof(tmp));
	if (xml)
-
		strlcat(tmp, "/vuln.xml.bz2", sizeof(tmp));
+
		strlcat(tmp, "/vuln.xml.bz2.XXXX", sizeof(tmp));
	else
-
		strlcat(tmp, "/auditfile.tbz", sizeof(tmp));
+
		strlcat(tmp, "/auditfile.tbz.XXXX", sizeof(tmp));

	if (stat(dest, &st) != -1) {
		t = st.st_mtime;