From a16b1c1fd9b8a0d7afe27819f0a464e585b71c3c Mon Sep 17 00:00:00 2001 From: Colin Percival Date: Mon, 5 Feb 2007 16:30:40 +0000 Subject: [PATCH] If (a == NULL), don't dereference (a) to record an error message. [1] Fallout from changing the skip API to use off_t instead of size_t: Print the skip length using %jd and cast to (intmax_t) instead of %d / (int), and if ARCHIVE_API_VERSION >= 2, allow the client skipper to be called for requests longer than SSIZE_MAX. [2] Approved by: kientzle Pointy hats to: kientzle [1], cperciva [2] MFC after: 3 days --- lib/libarchive/archive_read.c | 4 +--- lib/libarchive/archive_read_support_compression_none.c | 7 ++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/libarchive/archive_read.c b/lib/libarchive/archive_read.c index c24f1397f37b..857448383971 100644 --- a/lib/libarchive/archive_read.c +++ b/lib/libarchive/archive_read.c @@ -65,10 +65,8 @@ archive_read_new(void) unsigned char *nulls; a = (struct archive *)malloc(sizeof(*a)); - if (a == NULL) { - archive_set_error(a, ENOMEM, "Can't allocate archive object"); + if (a == NULL) return (NULL); - } memset(a, 0, sizeof(*a)); a->user_uid = geteuid(); diff --git a/lib/libarchive/archive_read_support_compression_none.c b/lib/libarchive/archive_read_support_compression_none.c index fe76310bdee2..1109488c3e4c 100644 --- a/lib/libarchive/archive_read_support_compression_none.c +++ b/lib/libarchive/archive_read_support_compression_none.c @@ -301,7 +301,11 @@ archive_decompressor_none_skip(struct archive *a, off_t request) /* * If a client_skipper was provided, try that first. */ +#if ARCHIVE_API_VERSION < 2 if ((a->client_skipper != NULL) && (request < SSIZE_MAX)) { +#else + if (a->client_skipper != NULL) { +#endif bytes_skipped = (a->client_skipper)(a, a->client_data, request); if (bytes_skipped < 0) { /* error */ @@ -333,7 +337,8 @@ archive_decompressor_none_skip(struct archive *a, off_t request) if (bytes_read == 0) { /* We hit EOF before we satisfied the skip request. */ archive_set_error(a, ARCHIVE_ERRNO_MISC, - "Truncated input file (need to skip %d bytes)", (int)request); + "Truncated input file (need to skip %jd bytes)", + (intmax_t)request); return (ARCHIVE_FATAL); } assert(bytes_read >= 0); /* precondition for cast below */