summaryrefslogtreecommitdiffstats
path: root/lib/libarchive
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2004-08-14 03:45:45 +0000
committerkientzle <kientzle@FreeBSD.org>2004-08-14 03:45:45 +0000
commit49a8ad2487b2329a538450200f1b1b2d698d6a23 (patch)
treec8c3ea449972625054a074cdd1e21e770642ffbb /lib/libarchive
parent136013f29f7390ade8ad49fc70a7a0ef804d10b3 (diff)
downloadFreeBSD-src-49a8ad2487b2329a538450200f1b1b2d698d6a23.zip
FreeBSD-src-49a8ad2487b2329a538450200f1b1b2d698d6a23.tar.gz
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.
Diffstat (limited to 'lib/libarchive')
-rw-r--r--lib/libarchive/Makefile2
-rw-r--r--lib/libarchive/archive_private.h2
-rw-r--r--lib/libarchive/archive_read.c15
-rw-r--r--lib/libarchive/archive_read_support_compression_bzip2.c41
-rw-r--r--lib/libarchive/archive_read_support_compression_compress.c6
-rw-r--r--lib/libarchive/archive_read_support_compression_gzip.c44
-rw-r--r--lib/libarchive/archive_read_support_format_cpio.c1
-rw-r--r--lib/libarchive/archive_read_support_format_tar.c13
-rw-r--r--lib/libarchive/archive_string.c6
-rw-r--r--lib/libarchive/archive_string_sprintf.c1
-rw-r--r--lib/libarchive/archive_util.c12
11 files changed, 104 insertions, 39 deletions
diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile
index 4ffff1b..b4be646 100644
--- a/lib/libarchive/Makefile
+++ b/lib/libarchive/Makefile
@@ -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}
diff --git a/lib/libarchive/archive_private.h b/lib/libarchive/archive_private.h
index 5fb4d9b..d9d4713 100644
--- a/lib/libarchive/archive_private.h
+++ b/lib/libarchive/archive_private.h
@@ -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
diff --git a/lib/libarchive/archive_read.c b/lib/libarchive/archive_read.c
index 2f9a998..39ff7a8 100644
--- a/lib/libarchive/archive_read.c
+++ b/lib/libarchive/archive_read.c
@@ -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. */
}
diff --git a/lib/libarchive/archive_read_support_compression_bzip2.c b/lib/libarchive/archive_read_support_compression_bzip2.c
index e65d0ac..8b82696 100644
--- a/lib/libarchive/archive_read_support_compression_bzip2.c
+++ b/lib/libarchive/archive_read_support_compression_bzip2.c
@@ -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);
}
diff --git a/lib/libarchive/archive_read_support_compression_compress.c b/lib/libarchive/archive_read_support_compression_compress.c
index 2a86c2f..93683eb 100644
--- a/lib/libarchive/archive_read_support_compression_compress.c
+++ b/lib/libarchive/archive_read_support_compression_compress.c
@@ -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);
}
diff --git a/lib/libarchive/archive_read_support_compression_gzip.c b/lib/libarchive/archive_read_support_compression_gzip.c
index 260e1d4..50da5ba 100644
--- a/lib/libarchive/archive_read_support_compression_gzip.c
+++ b/lib/libarchive/archive_read_support_compression_gzip.c
@@ -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);
}
diff --git a/lib/libarchive/archive_read_support_format_cpio.c b/lib/libarchive/archive_read_support_format_cpio.c
index 03af38f..b795337 100644
--- a/lib/libarchive/archive_read_support_format_cpio.c
+++ b/lib/libarchive/archive_read_support_format_cpio.c
@@ -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>
diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c
index e91ddc4..ecc42ad 100644
--- a/lib/libarchive/archive_read_support_format_tar.c
+++ b/lib/libarchive/archive_read_support_format_tar.c
@@ -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);
}
diff --git a/lib/libarchive/archive_string.c b/lib/libarchive/archive_string.c
index 323b611..0e92836 100644
--- a/lib/libarchive/archive_string.c
+++ b/lib/libarchive/archive_string.c
@@ -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);
}
diff --git a/lib/libarchive/archive_string_sprintf.c b/lib/libarchive/archive_string_sprintf.c
index c122369..174d2f9 100644
--- a/lib/libarchive/archive_string_sprintf.c
+++ b/lib/libarchive/archive_string_sprintf.c
@@ -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"
diff --git a/lib/libarchive/archive_util.c b/lib/libarchive/archive_util.c
index 2a44498..77b74ff 100644
--- a/lib/libarchive/archive_util.c
+++ b/lib/libarchive/archive_util.c
@@ -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);
+}
OpenPOWER on IntegriCloud