summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjoerg <joerg>2009-03-08 14:50:36 +0000
committerjoerg <joerg>2009-03-08 14:50:36 +0000
commit56f76fcd4dd7c935e1ee8038e62586c297666913 (patch)
tree1a6de50cc608aa738b71aa73162036cd0bb35da0 /pkgtools
parent0655b14a1d747d63d8fdd468c12621be6ede2a42 (diff)
downloadpkgsrc-56f76fcd4dd7c935e1ee8038e62586c297666913.tar.gz
pkg_install-20090307:
Simplify archive handling by depending on archive_read_finish and the close callback where needed. Fixes a file descriptor leak as side effect as reported by wiz.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/add/perform.c21
-rw-r--r--pkgtools/pkg_install/files/admin/main.c13
-rw-r--r--pkgtools/pkg_install/files/info/perform.c14
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h11
-rw-r--r--pkgtools/pkg_install/files/lib/pkg_io.c25
-rw-r--r--pkgtools/pkg_install/files/lib/pkg_signature.c24
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
7 files changed, 45 insertions, 67 deletions
diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c
index b087e4c5e9c..6e776168578 100644
--- a/pkgtools/pkg_install/files/add/perform.c
+++ b/pkgtools/pkg_install/files/add/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.83 2009/03/02 15:30:45 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.84 2009/03/08 14:50:36 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
@@ -6,7 +6,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: perform.c,v 1.83 2009/03/02 15:30:45 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.84 2009/03/08 14:50:36 joerg Exp $");
/*-
* Copyright (c) 2003 Grant Beattie <grant@NetBSD.org>
@@ -1154,7 +1154,7 @@ static int check_input(const char *line, size_t len)
}
static int
-check_signature(struct pkg_task *pkg, void *signature_cookie, int invalid_sig)
+check_signature(struct pkg_task *pkg, int invalid_sig)
{
char *line;
size_t len;
@@ -1244,22 +1244,20 @@ static int
pkg_do(const char *pkgpath, int mark_automatic, int top_level)
{
int status, invalid_sig;
- void *archive_cookie;
- void *signature_cookie;
struct pkg_task *pkg;
pkg = xcalloc(1, sizeof(*pkg));
status = -1;
- pkg->archive = find_archive(pkgpath, &archive_cookie, top_level);
+ pkg->archive = find_archive(pkgpath, top_level);
if (pkg->archive == NULL) {
warnx("no pkg found for '%s', sorry.", pkgpath);
goto clean_find_archive;
}
invalid_sig = pkg_verify_signature(&pkg->archive, &pkg->entry,
- &pkg->pkgname, &signature_cookie);
+ &pkg->pkgname);
if (pkg->archive == NULL)
goto clean_memory;
@@ -1271,7 +1269,7 @@ pkg_do(const char *pkgpath, int mark_automatic, int top_level)
if (pkg_parse_plist(pkg))
goto clean_memory;
- if (check_signature(pkg, &signature_cookie, invalid_sig))
+ if (check_signature(pkg, invalid_sig))
goto clean_memory;
if (check_vulnerable(pkg))
@@ -1415,13 +1413,10 @@ clean_memory:
free_buildinfo(pkg);
free_plist(&pkg->plist);
free_meta_data(pkg);
- if (pkg->archive) {
- archive_read_close(pkg->archive);
- close_archive(archive_cookie);
- }
+ if (pkg->archive)
+ archive_read_finish(pkg->archive);
free(pkg->other_version);
free(pkg->pkgname);
- pkg_free_signature(signature_cookie);
clean_find_archive:
free(pkg);
return status;
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index 1ce5fae9a69..f1b1938d692 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.47 2009/02/13 11:21:07 joerg Exp $ */
+/* $NetBSD: main.c,v 1.48 2009/03/08 14:50:36 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: main.c,v 1.47 2009/02/13 11:21:07 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.48 2009/03/08 14:50:36 joerg Exp $");
/*-
* Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
@@ -72,6 +72,10 @@ __RCSID("$NetBSD: main.c,v 1.47 2009/02/13 11:21:07 joerg Exp $");
#include <string.h>
#endif
+#ifndef BOOTSTRAP
+#include <archive.h>
+#endif
+
#include "admin.h"
#include "lib.h"
@@ -534,12 +538,11 @@ main(int argc, char *argv[])
audit_history(--argc, ++argv);
} else if (strcasecmp(argv[0], "check-signature") == 0) {
struct archive *pkg;
- void *cookie;
int rc;
rc = 0;
for (--argc, ++argv; argc > 0; --argc, ++argv) {
- pkg = open_archive(*argv, &cookie);
+ pkg = open_archive(*argv);
if (pkg == NULL) {
warnx("%s could not be opened", *argv);
continue;
@@ -547,7 +550,7 @@ main(int argc, char *argv[])
if (pkg_full_signature_check(&pkg))
rc = 1;
if (!pkg)
- close_archive(pkg);
+ archive_read_finish(pkg);
}
return rc;
} else if (strcasecmp(argv[0], "x509-sign-package") == 0) {
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index 5f605dd2ed3..bb6919dce43 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.53 2009/03/02 17:13:49 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.54 2009/03/08 14:50:36 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -13,7 +13,7 @@
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
-__RCSID("$NetBSD: perform.c,v 1.53 2009/03/02 17:13:49 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.54 2009/03/08 14:50:36 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@@ -339,27 +339,23 @@ pkg_do(const char *pkg)
errx(2, "Binary packages not supported during bootstrap");
#else
struct archive *archive;
- void *archive_cookie;
- void *signature_cookie;
struct archive_entry *entry;
char *pkgname;
- archive = open_archive(pkg, &archive_cookie);
+ archive = open_archive(pkg);
if (archive == NULL) {
warnx("can't find package `%s', skipped", pkg);
return -1;
}
pkgname = NULL;
entry = NULL;
- pkg_verify_signature(&archive, &entry, &pkgname,
- &signature_cookie);
+ pkg_verify_signature(&archive, &entry, &pkgname);
if (archive == NULL)
return -1;
free(pkgname);
meta = read_meta_data_from_archive(archive, entry);
- close_archive(archive_cookie);
- pkg_free_signature(signature_cookie);
+ archive_read_finish(archive);
if (!IS_URL(pkg))
binpkgfile = pkg;
#endif
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index 3fb35fb5146..5a454c58655 100644
--- a/pkgtools/pkg_install/files/lib/lib.h
+++ b/pkgtools/pkg_install/files/lib/lib.h
@@ -1,4 +1,4 @@
-/* $NetBSD: lib.h,v 1.49 2009/02/28 16:03:56 joerg Exp $ */
+/* $NetBSD: lib.h,v 1.50 2009/03/08 14:50:37 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -315,9 +315,8 @@ int recursive_remove(const char *, int);
struct archive;
struct archive_entry;
-struct archive *open_archive(const char *, void **);
-void close_archive(void *);
-struct archive *find_archive(const char *, void **, int);
+struct archive *open_archive(const char *);
+struct archive *find_archive(const char *, int);
void process_pkg_path(void);
/* Packing list */
@@ -376,10 +375,8 @@ void pkg_install_config(void);
void pkg_install_show_variable(const char *);
/* Package signature creation and validation */
-int pkg_verify_signature(struct archive **, struct archive_entry **, char **,
- void **);
+int pkg_verify_signature(struct archive **, struct archive_entry **, char **);
int pkg_full_signature_check(struct archive **);
-void pkg_free_signature(void *);
#ifdef HAVE_SSL
void pkg_sign_x509(const char *, const char *, const char *, const char *);
#endif
diff --git a/pkgtools/pkg_install/files/lib/pkg_io.c b/pkgtools/pkg_install/files/lib/pkg_io.c
index ff78414c984..85a12dc7f08 100644
--- a/pkgtools/pkg_install/files/lib/pkg_io.c
+++ b/pkgtools/pkg_install/files/lib/pkg_io.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pkg_io.c,v 1.5 2009/02/28 16:03:56 joerg Exp $ */
+/* $NetBSD: pkg_io.c,v 1.6 2009/03/08 14:50:37 joerg Exp $ */
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
* All rights reserved.
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: pkg_io.c,v 1.5 2009/02/28 16:03:56 joerg Exp $");
+__RCSID("$NetBSD: pkg_io.c,v 1.6 2009/03/08 14:50:37 joerg Exp $");
#include <archive.h>
#include <archive_entry.h>
@@ -93,11 +93,12 @@ fetch_archive_close(struct archive *a, void *client_data)
if (f->fetch != NULL)
fetchIO_close(f->fetch);
+ free(f);
return 0;
}
static struct archive *
-open_archive_by_url(struct url *url, void **cookie)
+open_archive_by_url(struct url *url)
{
struct fetch_archive *f;
struct archive *a;
@@ -115,12 +116,11 @@ open_archive_by_url(struct url *url, void **cookie)
return NULL;
}
- *cookie = f;
return a;
}
struct archive *
-open_archive(const char *url, void **cookie)
+open_archive(const char *url)
{
struct url *u;
struct archive *a;
@@ -133,25 +133,18 @@ open_archive(const char *url, void **cookie)
archive_read_close(a);
return NULL;
}
- *cookie = NULL;
return a;
}
if ((u = fetchParseURL(url)) == NULL)
return NULL;
- a = open_archive_by_url(u, cookie);
+ a = open_archive_by_url(u);
fetchFreeURL(u);
return a;
}
-void
-close_archive(void *cookie)
-{
- free(cookie);
-}
-
static int
strip_suffix(char *filename)
{
@@ -269,7 +262,7 @@ process_pkg_path(void)
}
struct archive *
-find_archive(const char *fname, void **cookie, int top_level)
+find_archive(const char *fname, int top_level)
{
struct archive *a;
struct pkg_path *pl;
@@ -294,7 +287,7 @@ find_archive(const char *fname, void **cookie, int top_level)
*last_slash = '/';
}
- a = open_archive(full_fname, cookie);
+ a = open_archive(full_fname);
if (a != NULL) {
free(full_fname);
return a;
@@ -334,7 +327,7 @@ find_archive(const char *fname, void **cookie, int top_level)
if (best_match == NULL)
return NULL;
- a = open_archive_by_url(best_match, cookie);
+ a = open_archive_by_url(best_match);
fetchFreeURL(best_match);
return a;
}
diff --git a/pkgtools/pkg_install/files/lib/pkg_signature.c b/pkgtools/pkg_install/files/lib/pkg_signature.c
index b270619a892..fb7aec34787 100644
--- a/pkgtools/pkg_install/files/lib/pkg_signature.c
+++ b/pkgtools/pkg_install/files/lib/pkg_signature.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pkg_signature.c,v 1.6 2009/03/02 14:59:14 joerg Exp $ */
+/* $NetBSD: pkg_signature.c,v 1.7 2009/03/08 14:50:37 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -7,7 +7,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: pkg_signature.c,v 1.6 2009/03/02 14:59:14 joerg Exp $");
+__RCSID("$NetBSD: pkg_signature.c,v 1.7 2009/03/08 14:50:37 joerg Exp $");
/*-
* Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
@@ -154,16 +154,14 @@ free_signature_int(struct signature_archive *state)
free(state);
}
-void
-pkg_free_signature(void *cookie)
+static int
+verify_signature_close_cb(struct archive *archive, void *cookie)
{
struct signature_archive *state = cookie;
- if (state == NULL)
- return;
-
archive_read_finish(state->archive);
free_signature_int(state);
+ return 0;
}
static int
@@ -311,7 +309,7 @@ cleanup:
int
pkg_verify_signature(struct archive **archive, struct archive_entry **entry,
- char **pkgname, void **cookie)
+ char **pkgname)
{
struct signature_archive *state;
struct archive_entry *my_entry;
@@ -321,7 +319,6 @@ pkg_verify_signature(struct archive **archive, struct archive_entry **entry,
int r, has_sig;
*pkgname = NULL;
- *cookie = NULL;
state = xmalloc(sizeof(*state));
state->sign_blocks = NULL;
@@ -403,15 +400,14 @@ pkg_verify_signature(struct archive **archive, struct archive_entry **entry,
a = archive_read_new();
archive_read_support_compression_all(a);
archive_read_support_format_all(a);
- if (archive_read_open(a, state, NULL, verify_signature_read_cb, NULL)) {
+ if (archive_read_open(a, state, NULL, verify_signature_read_cb,
+ verify_signature_close_cb)) {
warnx("Can't open signed package file");
archive_read_finish(a);
- free_signature_int(state);
goto no_valid_signature;
}
*archive = a;
*entry = NULL;
- *cookie = state;
return has_sig ? 0 : -1;
@@ -424,10 +420,9 @@ pkg_full_signature_check(struct archive **archive)
{
struct archive_entry *entry = NULL;
char *pkgname;
- void *cookie;
int r;
- if (pkg_verify_signature(archive, &entry, &pkgname, &cookie))
+ if (pkg_verify_signature(archive, &entry, &pkgname))
return -1;
if (pkgname == NULL)
return 0;
@@ -436,7 +431,6 @@ pkg_full_signature_check(struct archive **archive)
while ((r = archive_read_next_header(*archive, &entry)) == ARCHIVE_OK)
archive_read_data_skip(*archive);
- pkg_free_signature(cookie);
free(pkgname);
return r == ARCHIVE_EOF ? 0 : -1;
}
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index d8962aa240c..8afd834c516 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.117 2009/03/02 17:13:49 joerg Exp $ */
+/* $NetBSD: version.h,v 1.118 2009/03/08 14:50:37 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@@ -27,6 +27,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20090302"
+#define PKGTOOLS_VERSION "20090307"
#endif /* _INST_LIB_VERSION_H_ */