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
This commit is contained in:
Colin Percival 2007-02-05 16:30:40 +00:00
parent e9077dd658
commit a16b1c1fd9
2 changed files with 7 additions and 4 deletions

View File

@ -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();

View File

@ -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 */