From b292180ee1a6c0ce5a5dd60810baebd2a9d54b60 Mon Sep 17 00:00:00 2001 From: joerg Date: Thu, 27 Nov 2008 19:24:13 +0000 Subject: pkg_install-20081127: Correctly deal with short reads from fetchIO_read when loading pkg-vulnerabilities. --- pkgtools/pkg_install/files/admin/audit.c | 25 ++++++++++++++++++------- pkgtools/pkg_install/files/lib/version.h | 4 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pkgtools/pkg_install/files/admin/audit.c b/pkgtools/pkg_install/files/admin/audit.c index 72b9716006b..b421703a610 100644 --- a/pkgtools/pkg_install/files/admin/audit.c +++ b/pkgtools/pkg_install/files/admin/audit.c @@ -1,4 +1,4 @@ -/* $NetBSD: audit.c,v 1.8.2.5 2008/10/02 20:51:41 joerg Exp $ */ +/* $NetBSD: audit.c,v 1.8.2.6 2008/11/27 19:24:13 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -8,7 +8,7 @@ #include #endif #ifndef lint -__RCSID("$NetBSD: audit.c,v 1.8.2.5 2008/10/02 20:51:41 joerg Exp $"); +__RCSID("$NetBSD: audit.c,v 1.8.2.6 2008/11/27 19:24:13 joerg Exp $"); #endif /*- @@ -343,7 +343,8 @@ fetch_pkg_vulnerabilities(int argc, char **argv) { struct pkg_vulnerabilities *pv_check; char *buf, *decompressed_input; - size_t buf_len, decompressed_len; + size_t buf_len, buf_fetched, decompressed_len; + ssize_t cur_fetched; struct url_stat st; fetchIO *f; int fd; @@ -365,11 +366,21 @@ fetch_pkg_vulnerabilities(int argc, char **argv) buf_len = st.size; buf = xmalloc(buf_len + 1); + buf_fetched = 0; - if (fetchIO_read(f, buf, buf_len) != buf_len) - errx(EXIT_FAILURE, - "Failure during fetch of pkg-vulnerabilities: %s", - fetchLastErrString); + while (buf_fetched < buf_len) { + cur_fetched = fetchIO_read(f, buf + buf_fetched, + buf_len - buf_fetched); + if (cur_fetched == 0) + errx(EXIT_FAILURE, + "Truncated pkg-vulnerabilities received"); + else if (cur_fetched == -1) + errx(EXIT_FAILURE, + "IO error while fetching pkg-vulnerabilities: %s", + fetchLastErrString); + buf_fetched += cur_fetched; + } + buf[buf_len] = '\0'; if (decompress_buffer(buf, buf_len, &decompressed_input, diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h index 011fd41632c..19469e266d8 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.102.2.17 2008/10/02 20:51:41 joerg Exp $ */ +/* $NetBSD: version.h,v 1.102.2.18 2008/11/27 19:24:13 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 "20081003" +#define PKGTOOLS_VERSION "20081127" #endif /* _INST_LIB_VERSION_H_ */ -- cgit v1.2.3