From 2f723afb55381daaa3795c4ac5ee8e0915f5e314 Mon Sep 17 00:00:00 2001 From: joerg Date: Wed, 22 Apr 2009 19:18:06 +0000 Subject: pkg_install-20090422: Consider EOF during signature scan a fatal error. At the very least, the package is missing the +CONTENTS file at that point. Correctly reset the entry pointer in that case and make the meta data extraction stricter, avoiding NULL dereferences for invalid archives. Fixes pkg_info -X crash on empty files as reported by Daniel Horecki. --- pkgtools/pkg_install/files/info/perform.c | 14 ++++++++------ pkgtools/pkg_install/files/lib/pkg_signature.c | 10 ++++++---- pkgtools/pkg_install/files/lib/version.h | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c index de1ac33add8..cdfe5ad6c05 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.55 2009/03/09 19:58:45 joerg Exp $ */ +/* $NetBSD: perform.c,v 1.56 2009/04/22 19:18:06 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -13,7 +13,7 @@ #if HAVE_SYS_WAIT_H #include #endif -__RCSID("$NetBSD: perform.c,v 1.55 2009/03/09 19:58:45 joerg Exp $"); +__RCSID("$NetBSD: perform.c,v 1.56 2009/04/22 19:18:06 joerg Exp $"); /*- * Copyright (c) 2008 Joerg Sonnenberger . @@ -183,8 +183,10 @@ read_meta_data_from_archive(struct archive *archive, meta = xcalloc(1, sizeof(*meta)); last_descr = 0; - if (entry != NULL) + if (entry != NULL) { + r = ARCHIVE_OK; goto has_entry; + } while ((r = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) { has_entry: @@ -228,13 +230,13 @@ has_entry: if (descr->required_file) --found_required; } - if (found_required != 0) { + + meta->is_installed = 0; + if (found_required != 0 && r != ARCHIVE_OK && r != ARCHIVE_EOF) { free_pkg_meta(meta); meta = NULL; } - meta->is_installed = 0; - return meta; } #endif diff --git a/pkgtools/pkg_install/files/lib/pkg_signature.c b/pkgtools/pkg_install/files/lib/pkg_signature.c index fb7aec34787..710482e56a9 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.7 2009/03/08 14:50:37 joerg Exp $ */ +/* $NetBSD: pkg_signature.c,v 1.8 2009/04/22 19:18:06 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -7,7 +7,7 @@ #if HAVE_SYS_CDEFS_H #include #endif -__RCSID("$NetBSD: pkg_signature.c,v 1.7 2009/03/08 14:50:37 joerg Exp $"); +__RCSID("$NetBSD: pkg_signature.c,v 1.8 2009/04/22 19:18:06 joerg Exp $"); /*- * Copyright (c) 2008 Joerg Sonnenberger . @@ -179,9 +179,11 @@ retry: if (r == ARCHIVE_FATAL) { warnx("Cannot read from archive: %s", archive_error_string(archive)); - return -1; + } else { + warnx("Premature end of archive"); } - return 1; + *entry = NULL; + return -1; } if (strcmp(archive_entry_pathname(*entry), "//") == 0) { archive_read_data_skip(archive); diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h index 2edea7f38fd..e664698a58b 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.122 2009/04/10 04:03:11 reed Exp $ */ +/* $NetBSD: version.h,v 1.123 2009/04/22 19:18:06 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 "20090410" +#define PKGTOOLS_VERSION "20090422" #endif /* _INST_LIB_VERSION_H_ */ -- cgit v1.2.3