Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix symlinks checksums.
Vsevolod Stakhov committed 11 years ago
commit 4f56f4b75fec7b39df4aba944c76b63d7580891d
parent 06c1d32
5 files changed +44 -20
modified libpkg/pkg.c
@@ -1495,12 +1495,8 @@ pkg_test_filesum(struct pkg *pkg)
				return (EPKG_FATAL);
			}
			if (S_ISLNK(st.st_mode)) {
-
				char linkbuf[MAXPATHLEN];
-
				if ((ret = readlink(path, linkbuf, sizeof(linkbuf))) == -1) {
-
					pkg_emit_errno("pkg_create_from_dir", "readlink failed");
+
				if (pkg_symlink_cksum(path, NULL, sha256) != EPKG_OK)
					return (EPKG_FATAL);
-
				}
-
				sha256_buf(linkbuf, ret, sha256);
			}
			else {
				if (sha256_file(path, sha256) != EPKG_OK)
modified libpkg/pkg_create.c
@@ -2,6 +2,7 @@
 * Copyright (c) 2011-2013 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org>
+
 * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
@@ -89,14 +90,12 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
		}

		if (S_ISLNK(st.st_mode)) {
-
			char linkbuf[MAXPATHLEN];
-
			if ((ret = readlink(fpath, linkbuf, sizeof(linkbuf))) == -1) {
-
				pkg_emit_errno("pkg_create_from_dir", "readlink failed");
-
				return (EPKG_FATAL);
-
			}
+

			if (pkg_sum == NULL || pkg_sum[0] == '\0') {
-
				sha256_buf(linkbuf, ret, sha256);
-
				strlcpy(file->sum, sha256, sizeof(file->sum));
+
				if (pkg_symlink_cksum(fpath, root, sha256) == EPKG_OK)
+
					strlcpy(file->sum, sha256, sizeof(file->sum));
+
				else
+
					return (EPKG_FATAL);
			}
		}
		else {
modified libpkg/pkg_ports.c
@@ -382,15 +382,12 @@ file(struct plist *p, char *line, struct file_attr *a)
				regular = true;

		} else if (S_ISLNK(st.st_mode)) {
-
			char linkbuf[MAXPATHLEN];
-
			int len;
-
			if ((len = readlink(testpath, linkbuf, sizeof(linkbuf))) == -1) {
-
				pkg_emit_errno("file", "readlink failed");
-
				return (EPKG_FATAL);
+
			if (pkg_symlink_cksum(testpath, p->stage, sha256) == EPKG_OK) {
+
				buf = sha256;
+
				regular = false;
			}
-
			sha256_buf(linkbuf, len, sha256);
-
			buf = sha256;
-
			regular = false;
+
			else
+
				return (EPKG_FATAL);
		}

		if (regular) {
modified libpkg/private/pkg.h
@@ -613,4 +613,6 @@ const char* pkg_checksum_type_to_string(pkg_checksum_type_t type);
size_t pkg_checksum_type_size(pkg_checksum_type_t type);
int pkg_checksum_calculate(struct pkg *pkg, struct pkgdb *db);

+
int pkg_symlink_cksum(const char *path, const char *root, char *cksum);
+

#endif
modified libpkg/utils.c
@@ -875,3 +875,33 @@ print_trace(void)
	free(strings);
#endif
}
+

+
int
+
pkg_symlink_cksum(const char *path, const char *root, char *cksum)
+
{
+
	char linkbuf[MAXPATHLEN];
+
	const char *lnk;
+
	int ret;
+

+
	if ((ret = readlink(path, linkbuf, sizeof(linkbuf) - 1)) == -1) {
+
		pkg_emit_errno("pkg_symlink_cksum", "readlink failed");
+
		return (EPKG_FATAL);
+
	}
+

+
	/* Null terminate */
+
	linkbuf[ret] = '\0';
+
	lnk = linkbuf;
+
	if (root != NULL) {
+
		/* Skip root from checksum, as it is meaningless */
+
		if (strncmp(root, linkbuf, strlen(root)) == 0) {
+
			lnk += strlen(root);
+
		}
+
	}
+
	/* Skip heading slashes */
+
	while(*lnk == '/')
+
		lnk ++;
+

+
	sha256_buf(lnk, ret, cksum);
+

+
	return (EPKG_OK);
+
}