Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use fstat to get the size of the opened fd to avoir a potential race
Baptiste Daroussin committed 10 years ago
commit 47a35b30cdf8930a80acd97dd7bd79338e0ac38e
parent 9d1aad7
1 file changed +4 -2
modified libpkg/pkg_audit.c
@@ -860,11 +860,13 @@ pkg_audit_load(struct pkg_audit *audit, const char *fname)
	void *mem;
	struct stat st;

-
	if (stat(fname, &st) == -1)
+
	if ((fd = open(fname, O_RDONLY)) == -1)
		return (EPKG_FATAL);

-
	if ((fd = open(fname, O_RDONLY)) == -1)
+
	if (fstat(fd, &st) == -1) {
+
		close(fd);
		return (EPKG_FATAL);
+
	}

	if ((mem = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)) == MAP_FAILED) {
		close(fd);