Eliminate reliance on non-portable <err.h> by implementing a very
simple errx() function. Improve behavior when bzlib/zlib are missing by detecting and issuing an error message on attempts to read gzip/bzip2 compressed archives.
This commit is contained in:
parent
136013f29f
commit
49a8ad2487
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
LIB= archive
|
||||
VERSION= 1.01.010
|
||||
VERSION= 1.01.013
|
||||
ARCHIVE_API_FEATURE= 2
|
||||
ARCHIVE_API_VERSION= 1
|
||||
SHLIB_MAJOR= ${ARCHIVE_API_VERSION}
|
||||
|
@ -235,6 +235,8 @@ int __archive_read_register_compression(struct archive *a,
|
||||
int (*bid)(const void *, size_t),
|
||||
int (*init)(struct archive *, const void *, size_t));
|
||||
|
||||
void __archive_errx(int retvalue, const char *msg);
|
||||
|
||||
#define err_combine(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
#endif
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "archive_platform.h"
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -110,8 +109,8 @@ archive_read_open(struct archive *a, void *client_data,
|
||||
archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW);
|
||||
|
||||
if (reader == NULL)
|
||||
errx(1,
|
||||
"Fatal: No reader function provided to archive_read_open");
|
||||
__archive_errx(1,
|
||||
"No reader function provided to archive_read_open");
|
||||
|
||||
a->client_reader = reader;
|
||||
a->client_opener = opener;
|
||||
@ -181,7 +180,7 @@ choose_decompressor(struct archive *a, const void *buffer, size_t bytes_read)
|
||||
* and demands a quick and definitive abort.
|
||||
*/
|
||||
if (best_bid_slot < 0)
|
||||
errx(1, "Fatal: No decompressors were registered; you "
|
||||
__archive_errx(1, "No decompressors were registered; you "
|
||||
"must call at least one "
|
||||
"archive_read_support_compression_XXX function in order "
|
||||
"to successfully read an archive.");
|
||||
@ -304,7 +303,7 @@ choose_format(struct archive *a)
|
||||
* and demands a quick and definitive abort.
|
||||
*/
|
||||
if (best_bid_slot < 0)
|
||||
errx(1, "Fatal: No formats were registered; you must "
|
||||
__archive_errx(1, "No formats were registered; you must "
|
||||
"invoke at least one archive_read_support_format_XXX "
|
||||
"function in order to successfully read an archive.");
|
||||
|
||||
@ -526,7 +525,8 @@ __archive_read_register_format(struct archive *a,
|
||||
}
|
||||
}
|
||||
|
||||
errx(1, "Fatal: Not enough slots for format registration");
|
||||
__archive_errx(1, "Not enough slots for format registration");
|
||||
return (ARCHIVE_FATAL); /* Never actually called. */
|
||||
}
|
||||
|
||||
/*
|
||||
@ -554,5 +554,6 @@ __archive_read_register_compression(struct archive *a,
|
||||
}
|
||||
}
|
||||
|
||||
errx(1, "Fatal: Not enough slots for compression registration");
|
||||
__archive_errx(1, "Not enough slots for compression registration");
|
||||
return (ARCHIVE_FATAL); /* Never actually executed. */
|
||||
}
|
||||
|
@ -26,21 +26,20 @@
|
||||
|
||||
#include "archive_platform.h"
|
||||
|
||||
/* Don't compile this if we don't have bzlib. */
|
||||
#if HAVE_BZLIB_H
|
||||
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_BZLIB_H
|
||||
#include <bzlib.h>
|
||||
#endif
|
||||
|
||||
#include "archive.h"
|
||||
#include "archive_private.h"
|
||||
|
||||
#if HAVE_BZLIB_H
|
||||
struct private_data {
|
||||
bz_stream stream;
|
||||
unsigned char *uncompressed_buffer;
|
||||
@ -49,12 +48,15 @@ struct private_data {
|
||||
int64_t total_out;
|
||||
};
|
||||
|
||||
static int bid(const void *, size_t);
|
||||
static int finish(struct archive *);
|
||||
static int init(struct archive *, const void *, size_t);
|
||||
static ssize_t read_ahead(struct archive *, const void **, size_t);
|
||||
static ssize_t read_consume(struct archive *, size_t);
|
||||
static int drive_decompressor(struct archive *a, struct private_data *);
|
||||
#endif
|
||||
|
||||
/* These two functions are defined even if we lack bzlib. See below. */
|
||||
static int bid(const void *, size_t);
|
||||
static int init(struct archive *, const void *, size_t);
|
||||
|
||||
int
|
||||
archive_read_support_compression_bzip2(struct archive *a)
|
||||
@ -116,6 +118,28 @@ bid(const void *buff, size_t len)
|
||||
return (bits_checked);
|
||||
}
|
||||
|
||||
#ifndef HAVE_BZLIB_H
|
||||
|
||||
/*
|
||||
* If we don't have bzlib on this system, we can't actually do the
|
||||
* decompression. We can, however, still detect bzip2-compressed
|
||||
* archives and emit a useful message.
|
||||
*/
|
||||
static int
|
||||
init(struct archive *a, const void *buff, size_t n)
|
||||
{
|
||||
(void)a; /* UNUSED */
|
||||
(void)buff; /* UNUSED */
|
||||
(void)n; /* UNUSED */
|
||||
|
||||
archive_set_error(a, -1,
|
||||
"This version of libarchive was compiled without bzip2 support");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Setup the callbacks.
|
||||
*/
|
||||
@ -264,9 +288,8 @@ read_consume(struct archive *a, size_t n)
|
||||
a->file_position += n;
|
||||
state->read_next += n;
|
||||
if (state->read_next > state->stream.next_out)
|
||||
errx(1, "Internal error: Request to consume too many "
|
||||
"bytes from %s decompressor.\n",
|
||||
a->compression_name);
|
||||
__archive_errx(1, "Request to consume too many "
|
||||
"bytes from bzip2 decompressor");
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@
|
||||
#include "archive_platform.h"
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -318,9 +317,8 @@ read_consume(struct archive *a, size_t n)
|
||||
a->file_position += n;
|
||||
state->read_next += n;
|
||||
if (state->read_next > state->next_out)
|
||||
errx(1, "Internal error: Request to consume too many "
|
||||
"bytes from %s decompressor.\n",
|
||||
a->compression_name);
|
||||
__archive_errx(1, "Request to consume too many "
|
||||
"bytes from compress decompressor");
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
@ -26,22 +26,21 @@
|
||||
|
||||
#include "archive_platform.h"
|
||||
|
||||
/* Don't compile this if we don't have zlib. */
|
||||
#if HAVE_ZLIB_H
|
||||
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_ZLIB_H
|
||||
#include <zlib.h>
|
||||
|
||||
#include <err.h> /* zlib.h is borked, so must precede err.h */
|
||||
#endif
|
||||
|
||||
#include "archive.h"
|
||||
#include "archive_private.h"
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
struct private_data {
|
||||
z_stream stream;
|
||||
unsigned char *uncompressed_buffer;
|
||||
@ -52,12 +51,15 @@ struct private_data {
|
||||
char header_done;
|
||||
};
|
||||
|
||||
static int bid(const void *, size_t);
|
||||
static int finish(struct archive *);
|
||||
static int init(struct archive *, const void *, size_t);
|
||||
static ssize_t read_ahead(struct archive *, const void **, size_t);
|
||||
static ssize_t read_consume(struct archive *, size_t);
|
||||
static int drive_decompressor(struct archive *a, struct private_data *);
|
||||
#endif
|
||||
|
||||
/* These two functions are defined even if we lack zlib. See below. */
|
||||
static int bid(const void *, size_t);
|
||||
static int init(struct archive *, const void *, size_t);
|
||||
|
||||
int
|
||||
archive_read_support_compression_gzip(struct archive *a)
|
||||
@ -117,6 +119,29 @@ bid(const void *buff, size_t len)
|
||||
return (bits_checked);
|
||||
}
|
||||
|
||||
|
||||
#ifndef HAVE_ZLIB_H
|
||||
|
||||
/*
|
||||
* If we don't have zlib on this system, we can't actually do the
|
||||
* decompression. We can, however, still detect gzip-compressed
|
||||
* archives and emit a useful message.
|
||||
*/
|
||||
static int
|
||||
init(struct archive *a, const void *buff, size_t n)
|
||||
{
|
||||
(void)a; /* UNUSED */
|
||||
(void)buff; /* UNUSED */
|
||||
(void)n; /* UNUSED */
|
||||
|
||||
archive_set_error(a, -1,
|
||||
"This version of libarchive was compiled without gzip support");
|
||||
return (ARCHIVE_FATAL);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Setup the callbacks.
|
||||
*/
|
||||
@ -269,9 +294,8 @@ read_consume(struct archive *a, size_t n)
|
||||
a->file_position += n;
|
||||
state->read_next += n;
|
||||
if (state->read_next > state->stream.next_out)
|
||||
errx(1, "Internal error: Request to consume too many "
|
||||
"bytes from %s decompressor.\n",
|
||||
a->compression_name);
|
||||
__archive_errx(1, "Request to consume too many "
|
||||
"bytes from gzip decompressor");
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
/* #include <stdint.h> */ /* See archive_platform.h */
|
||||
#include <stdlib.h>
|
||||
|
@ -1602,10 +1602,17 @@ UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n)
|
||||
return ((size_t)-1);
|
||||
}
|
||||
if (pwc != NULL) {
|
||||
if (wch < WCHAR_MAX)
|
||||
*pwc = (wchar_t)wch;
|
||||
else
|
||||
/* Assign the value to the output; out-of-range values
|
||||
* just get truncated. */
|
||||
*pwc = (wchar_t)wch;
|
||||
#ifdef WCHAR_MAX
|
||||
/*
|
||||
* If platform has WCHAR_MAX, we can do something
|
||||
* more sensible with out-of-range values.
|
||||
*/
|
||||
if (wch >= WCHAR_MAX)
|
||||
*pwc = '?';
|
||||
#endif
|
||||
}
|
||||
return (wch == L'\0' ? 0 : len);
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ __FBSDID("$FreeBSD$");
|
||||
* strings while minimizing heap activity.
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "archive_private.h"
|
||||
#include "archive_string.h"
|
||||
|
||||
struct archive_string *
|
||||
@ -68,8 +68,10 @@ __archive_string_ensure(struct archive_string *as, size_t s)
|
||||
while (as->buffer_length < s)
|
||||
as->buffer_length *= 2;
|
||||
as->s = realloc(as->s, as->buffer_length);
|
||||
/* TODO: Return null instead and fix up all of our callers to
|
||||
* handle this correctly. */
|
||||
if (as->s == NULL)
|
||||
errx(1,"Out of memory");
|
||||
__archive_errx(1, "Out of memory");
|
||||
return (as);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
|
||||
* the core code, so it cannot easily be omitted.)
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "archive_string.h"
|
||||
|
@ -28,7 +28,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "archive.h"
|
||||
@ -149,3 +149,13 @@ archive_set_error(struct archive *a, int error_number, const char *fmt, ...)
|
||||
a->error = a->error_string.s;
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void
|
||||
__archive_errx(int retvalue, const char *msg)
|
||||
{
|
||||
static const char *msg1 = "Fatal Internal Error in libarchive: ";
|
||||
write(2, msg1, strlen(msg1));
|
||||
write(2, msg, strlen(msg));
|
||||
write(2, "\n", 1);
|
||||
exit(retvalue);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user