diff options
author | kientzle <kientzle@FreeBSD.org> | 2007-07-15 19:13:59 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2007-07-15 19:13:59 +0000 |
commit | c2571d8b749d2251abc1a93a11f2cf9c5b3d9cef (patch) | |
tree | 277b7c303ff4bb3a5583547383d51d714527e1c8 /lib/libarchive/archive_read_support_format_tar.c | |
parent | 235eaa1de0144fe4b74f0955091911fb67fffa86 (diff) | |
download | FreeBSD-src-c2571d8b749d2251abc1a93a11f2cf9c5b3d9cef.zip FreeBSD-src-c2571d8b749d2251abc1a93a11f2cf9c5b3d9cef.tar.gz |
archive_string_ensure() used to call exit(3) if it
couldn't allocate more memory for a string. Change
this so it returns NULL in that case, and update
all of its callers to handle the error. Some of
those callers can now return errors back to the
client instead of calling exit(3).
Approved by: re (bmah)
Diffstat (limited to 'lib/libarchive/archive_read_support_format_tar.c')
-rw-r--r-- | lib/libarchive/archive_read_support_format_tar.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c index c5d33f8..4559412 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/lib/libarchive/archive_read_support_format_tar.c @@ -895,8 +895,14 @@ read_body_to_string(struct archive_read *a, struct tar *tar, return (ARCHIVE_FATAL); } + /* Fail if we can't make our buffer big enough. */ + if (archive_string_ensure(as, size+1) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } + /* Read the body into the string. */ - archive_string_ensure(as, size+1); padded_size = (size + 511) & ~ 511; dest = as->s; while (padded_size > 0) { @@ -2020,7 +2026,11 @@ readline(struct archive_read *a, struct tar *tar, const char **start) } /* Otherwise, we need to accumulate in a line buffer. */ for (;;) { - archive_string_ensure(&tar->line, total_size + bytes_read); + if (archive_string_ensure(&tar->line, total_size + bytes_read) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate working buffer"); + return (ARCHIVE_FATAL); + } memcpy(tar->line.s + total_size, t, bytes_read); (a->decompressor->consume)(a, bytes_read); total_size += bytes_read; |