Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Avoid getcwd usage when parsing manifests
Vsevolod Stakhov committed 9 years ago
commit ef1b2d0b3bcf71438204322c6d157c0895f51a62
parent af6a4b7
3 files changed +38 -10
modified libpkg/pkg_manifest.c
@@ -3,7 +3,7 @@
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2013-2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -13,7 +13,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -35,6 +35,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+
#include <fcntl.h>
#include <ucl.h>

#include "sha256.h"
@@ -871,22 +872,31 @@ pkg_parse_manifest_file(struct pkg *pkg, const char *file, struct pkg_manifest_k
{
	struct ucl_parser *p = NULL;
	ucl_object_t *obj = NULL;
-
	int rc;
+
	int rc, fd;

	assert(pkg != NULL);
	assert(file != NULL);

	pkg_debug(1, "Parsing manifest from '%s'", file);
+
	fd = open(file, O_RDONLY);
+

+
	if (fd == -1) {
+
		pkg_emit_error("Error loading manifest from %s: %s",
+
				    file, strerror(errno));
+
	}

	errno = 0;
	p = ucl_parser_new(0);
-
	if (!ucl_parser_add_file(p, file)) {
+
	if (!ucl_parser_add_fd(p, fd)) {
		pkg_emit_error("Error parsing manifest: %s",
		    ucl_parser_get_error(p));
		ucl_parser_free(p);
+
		close(fd);
		return (EPKG_FATAL);
	}

+
	close(fd);
+

	if ((obj = ucl_parser_get_object(p)) == NULL) {
		ucl_parser_free(p);
		return (EPKG_FATAL);
modified libpkg/pkg_ports.c
@@ -3,7 +3,7 @@
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2012-2013 Bryan Drewery <bdrewery@FreeBSD.org>
 * All rights reserved.
-
 * 
+
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
@@ -13,7 +13,7 @@
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
-
 * 
+
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -36,6 +36,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
+
#include <fcntl.h>
#include <unistd.h>
#include <uthash.h>

@@ -943,7 +944,7 @@ external_keyword(struct plist *plist, char *keyword, char *line, struct file_att
	struct ucl_parser *parser;
	const char *keyword_dir = NULL;
	char keyfile_path[MAXPATHLEN];
-
	int ret = EPKG_UNKNOWN;
+
	int ret = EPKG_UNKNOWN, fd;
	ucl_object_t *o, *schema;
	struct ucl_schema_error err;

@@ -957,14 +958,22 @@ external_keyword(struct plist *plist, char *keyword, char *line, struct file_att
		    "%s/%s.ucl", keyword_dir, keyword);
	}

+
	fd = open(keyfile_path, O_RDONLY);
+
	if (fd == -1) {
+
		pkg_emit_error("cannot load keyword from %s: %s",
+
				keyfile_path, strerror(errno));
+
	}
+

	parser = ucl_parser_new(0);
-
	if (!ucl_parser_add_file(parser, keyfile_path)) {
+
	if (!ucl_parser_add_fd(parser, fd)) {
		pkg_emit_error("cannot parse keyword: %s",
				ucl_parser_get_error(parser));
		ucl_parser_free(parser);
+
		close(fd);
		return (EPKG_UNKNOWN);
	}

+
	close(fd);
	o = ucl_parser_get_object(parser);
	ucl_parser_free(parser);

modified libpkg/pkg_repo.c
@@ -1010,18 +1010,27 @@ pkg_repo_load_fingerprint(const char *dir, const char *filename)
	struct ucl_parser *p = NULL;
	char path[MAXPATHLEN];
	struct fingerprint *f = NULL;
+
	int fd;

	snprintf(path, sizeof(path), "%s/%s", dir, filename);
+
	fd = open(path, O_RDONLY);
+
	if (fd == -1) {
+
		pkg_emit_error("cannot load fingerprints from %s: %s",
+
				path, strerror(errno));
+
		return (NULL);
+
	}

	p = ucl_parser_new(0);

-
	if (!ucl_parser_add_file(p, path)) {
-
		pkg_emit_error("%s", ucl_parser_get_error(p));
+
	if (!ucl_parser_add_fd(p, fd)) {
+
		pkg_emit_error("cannot parse fingerprints: %s", ucl_parser_get_error(p));
		ucl_parser_free(p);
+
		close(fd);
		return (NULL);
	}

	obj = ucl_parser_get_object(p);
+
	close(fd);

	if (obj->type == UCL_OBJECT)
		f = pkg_repo_parse_fingerprint(obj);