Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a single function to validate ABIs
Baptiste Daroussin committed 12 years ago
commit 2236f4c742127d87f7969680f273fe77b43da761
parent c266102
4 files changed +25 -15
modified libpkg/pkg_add.c
@@ -35,10 +35,10 @@
#include <stdbool.h>
#include <string.h>
#include <errno.h>
-
#include <fnmatch.h>

#include "pkg.h"
#include "private/event.h"
+
#include "private/utils.h"
#include "private/pkg.h"

static int
@@ -153,7 +153,6 @@ int
pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_key *keys)
{
	const char	*arch;
-
	const char	*myarch;
	const char	*origin;
	const char	*name;
	struct archive	*a;
@@ -201,13 +200,9 @@ pkg_add(struct pkgdb *db, const char *path, unsigned flags, struct pkg_manifest_
	 * Check the architecture
	 */

-
	pkg_config_string(PKG_CONFIG_ABI, &myarch);
	pkg_get(pkg, PKG_ARCH, &arch, PKG_ORIGIN, &origin, PKG_NAME, &name);

-
	if (fnmatch(arch, myarch, FNM_CASEFOLD) == FNM_NOMATCH &&
-
	    strncmp(arch, myarch, strlen(myarch)) != 0) {
-
		pkg_emit_error("wrong architecture: %s instead of %s",
-
		    arch, myarch);
+
	if (!is_valid_abi(arch, true)) {
		if ((flags & PKG_ADD_FORCE) == 0) {
			retcode = EPKG_FATAL;
			goto cleanup;
modified libpkg/private/utils.h
@@ -98,6 +98,7 @@ int rsa_verify_cert(const char *path, unsigned char *cert,
    int certlen, unsigned char *sig, int sig_len, int fd);

bool is_hardlink(struct hardlinks *hl, struct stat *st);
+
bool is_valid_abi(const char *arch, bool emit_error);

struct dns_srvinfo *
	dns_getsrvinfo(const char *zone);
modified libpkg/update.c
@@ -525,7 +525,7 @@ pkg_register_repo(struct pkg_repo *repo, sqlite3 *sqlite)

static int
pkg_add_from_manifest(char *buf, const char *origin, long offset,
-
		const char *manifest_digest, const char *local_arch, sqlite3 *sqlite,
+
		const char *manifest_digest, sqlite3 *sqlite,
		struct pkg_manifest_key **keys, struct pkg **p)
{
	int rc = EPKG_OK;
@@ -560,9 +560,8 @@ pkg_add_from_manifest(char *buf, const char *origin, long offset,
		rc = EPKG_FATAL;
		goto cleanup;
	}
-
	if (pkg_arch == NULL || strcmp(pkg_arch, local_arch) != 0) {
-
		pkg_emit_error("package %s is built for %s arch, and local arch is %s",
-
				origin, pkg_arch ? pkg_arch : "NULL", local_arch);
+

+
	if (pkg_arch == NULL || !is_valid_abi(pkg_arch, true)) {
		rc = EPKG_FATAL;
		goto cleanup;
	}
@@ -611,7 +610,6 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
	time_t local_t = *mtime;
	struct pkg_increment_task_item *ldel = NULL, *ladd = NULL,
			*item, *tmp_item;
-
	const char *myarch;
	struct pkg_manifest_key *keys = NULL;
	size_t linecap = 0;
	ssize_t linelen;
@@ -715,8 +713,6 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
		free(item);
	}

-
	pkg_config_string(PKG_CONFIG_ABI, &myarch);
-

	pkg_debug(1, "Pkgrepo, pushing new entries for '%s'", name);
	pkg = NULL;

@@ -731,7 +727,7 @@ pkg_update_incremental(const char *name, struct pkg_repo *repo, time_t *mtime)
	HASH_ITER(hh, ladd, item, tmp_item) {
		if (rc == EPKG_OK) {
			rc = pkg_add_from_manifest(map + item->offset, item->origin,
-
			    len - item->offset, item->digest, myarch, sqlite, &keys, &pkg);
+
			    len - item->offset, item->digest, sqlite, &keys, &pkg);
		}
		free(item->origin);
		free(item->digest);
modified libpkg/utils.c
@@ -40,6 +40,7 @@
#include <uthash.h>
#include <utlist.h>
#include <ctype.h>
+
#include <fnmatch.h>

#include "pkg.h"
#include "private/event.h"
@@ -458,6 +459,23 @@ is_hardlink(struct hardlinks *hl, struct stat *st)
	return (true);
}

+
bool
+
is_valid_abi(const char *arch, bool emit_error) {
+
	const char *myarch;
+

+
	pkg_config_string(PKG_CONFIG_ABI, &myarch);
+

+
	if (fnmatch(arch, myarch, FNM_CASEFOLD) == FNM_NOMATCH &&
+
	    strncmp(arch, myarch, strlen(myarch)) != 0) {
+
		if (emit_error)
+
			pkg_emit_error("wrong architecture: %s instead of %s",
+
			    arch, myarch);
+
		return (false);
+
	}
+

+
	return (true);
+
}
+

static void yaml_mapping_to_object(ucl_object_t *obj, yaml_document_t *doc, yaml_node_t *node);

static void