diff options
author | Tim Kientzle <kientzle@FreeBSD.org> | 2005-09-21 04:25:06 +0000 |
---|---|---|
committer | Tim Kientzle <kientzle@FreeBSD.org> | 2005-09-21 04:25:06 +0000 |
commit | 8aaa8fe7337c8fff293e7688aff704046ee065cc (patch) | |
tree | 6f61f48765d8080ef9566d9cbfc0f3e97cefd834 /lib/libarchive/archive_read_support_format_tar.c | |
parent | c114cc6c3fb9ee5ebb0e0eac7f318bad34a98150 (diff) | |
download | src-8aaa8fe7337c8fff293e7688aff704046ee065cc.tar.gz src-8aaa8fe7337c8fff293e7688aff704046ee065cc.zip |
Add a lot of error checks, based on the patches provided by Dan Lukes.
Also fixes a memory leak reported by Andrew Turner.
PR: bin/83476
Thanks to: Dan Lukes, Andrew Turner
Notes
Notes:
svn path=/head/; revision=150407
Diffstat (limited to 'lib/libarchive/archive_read_support_format_tar.c')
-rw-r--r-- | lib/libarchive/archive_read_support_format_tar.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c index b79140d4b5b0..c565cecf6699 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/lib/libarchive/archive_read_support_format_tar.c @@ -230,6 +230,10 @@ archive_read_support_format_tar(struct archive *a) int r; tar = malloc(sizeof(*tar)); + if (tar == NULL) { + archive_set_error(a, ENOMEM, "Can't allocate tar data"); + return (ARCHIVE_FATAL); + } memset(tar, 0, sizeof(*tar)); r = __archive_read_register_format(a, tar, @@ -1080,14 +1084,22 @@ pax_header(struct archive *a, struct tar *tar, struct archive_entry *entry, /* Ensure pax_entry buffer is big enough. */ if (tar->pax_entry_length <= line_length) { + wchar_t *old_entry = tar->pax_entry; + if (tar->pax_entry_length <= 0) tar->pax_entry_length = 1024; while (tar->pax_entry_length <= line_length + 1) tar->pax_entry_length *= 2; - /* XXX Error handling here */ + old_entry = tar->pax_entry; tar->pax_entry = realloc(tar->pax_entry, tar->pax_entry_length * sizeof(wchar_t)); + if (tar->pax_entry == NULL) { + free(old_entry); + archive_set_error(a, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } } /* Decode UTF-8 to wchar_t, null-terminate result. */ @@ -1409,6 +1421,8 @@ gnu_parse_sparse_data(struct archive *a, struct tar *tar, while (length > 0 && sparse->offset[0] != 0) { p = malloc(sizeof(*p)); + if (p == NULL) + __archive_errx(1, "Out of memory"); memset(p, 0, sizeof(*p)); if (last != NULL) last->next = p; |