pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files pkg_install-20090307:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/9f242d5a284d
branches:  trunk
changeset: 555756:9f242d5a284d
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Mar 08 14:50:36 2009 +0000

description:
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:

 pkgtools/pkg_install/files/add/perform.c       |  21 ++++++++-------------
 pkgtools/pkg_install/files/admin/main.c        |  13 ++++++++-----
 pkgtools/pkg_install/files/info/perform.c      |  14 +++++---------
 pkgtools/pkg_install/files/lib/lib.h           |  11 ++++-------
 pkgtools/pkg_install/files/lib/pkg_io.c        |  25 +++++++++----------------
 pkgtools/pkg_install/files/lib/pkg_signature.c |  24 +++++++++---------------
 pkgtools/pkg_install/files/lib/version.h       |   4 ++--
 7 files changed, 45 insertions(+), 67 deletions(-)

diffs (truncated from 421 to 300 lines):

diff -r 7dd96b13c2ca -r 9f242d5a284d pkgtools/pkg_install/files/add/perform.c
--- a/pkgtools/pkg_install/files/add/perform.c  Sun Mar 08 14:04:29 2009 +0000
+++ b/pkgtools/pkg_install/files/add/perform.c  Sun Mar 08 14:50:36 2009 +0000
@@ -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@localhost>
@@ -1154,7 +1154,7 @@
 }
 
 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 @@
 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 @@
        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 @@
        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 -r 7dd96b13c2ca -r 9f242d5a284d pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c   Sun Mar 08 14:04:29 2009 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c   Sun Mar 08 14:50:36 2009 +0000
@@ -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 @@
 #include <string.h>
 #endif
 
+#ifndef BOOTSTRAP
+#include <archive.h>
+#endif
+
 #include "admin.h"
 #include "lib.h"
 
@@ -534,12 +538,11 @@
                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 @@
                        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 -r 7dd96b13c2ca -r 9f242d5a284d pkgtools/pkg_install/files/info/perform.c
--- a/pkgtools/pkg_install/files/info/perform.c Sun Mar 08 14:04:29 2009 +0000
+++ b/pkgtools/pkg_install/files/info/perform.c Sun Mar 08 14:50:36 2009 +0000
@@ -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@localhost>.
@@ -339,27 +339,23 @@
                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 -r 7dd96b13c2ca -r 9f242d5a284d pkgtools/pkg_install/files/lib/lib.h
--- a/pkgtools/pkg_install/files/lib/lib.h      Sun Mar 08 14:04:29 2009 +0000
+++ b/pkgtools/pkg_install/files/lib/lib.h      Sun Mar 08 14:50:36 2009 +0000
@@ -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 @@
 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_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 -r 7dd96b13c2ca -r 9f242d5a284d pkgtools/pkg_install/files/lib/pkg_io.c
--- a/pkgtools/pkg_install/files/lib/pkg_io.c   Sun Mar 08 14:04:29 2009 +0000
+++ b/pkgtools/pkg_install/files/lib/pkg_io.c   Sun Mar 08 14:50:36 2009 +0000
@@ -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@localhost>.
  * 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 @@
 
        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 @@
                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 @@
                        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 @@
 }
 
 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 @@
                *last_slash = '/';
        }
 
-       a = open_archive(full_fname, cookie);
+       a = open_archive(full_fname);
        if (a != NULL) {



Home | Main Index | Thread Index | Old Index