diff options
author | Brad King <brad.king@kitware.com> | 2014-04-03 18:37:54 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-04-03 19:02:49 (GMT) |
commit | 2f1978632b709a9370b3cb1137375c05351d149c (patch) | |
tree | 85980710818211b8188709643e6714e8839feee9 /Utilities/cmlibarchive/libarchive/archive_write.c | |
parent | 23e4666cf57c31c719472debba83a43f54d351d8 (diff) | |
parent | 64713ae3ffddf6fbbfa7ea762c3d756cb245a066 (diff) | |
download | CMake-2f1978632b709a9370b3cb1137375c05351d149c.zip CMake-2f1978632b709a9370b3cb1137375c05351d149c.tar.gz CMake-2f1978632b709a9370b3cb1137375c05351d149c.tar.bz2 |
Merge branch 'libarchive-upstream' into update-libarchive
Resolve conflicts in favor of the upstream side where possible.
Resolve a logical conflict in archive_windows.h where the upstream
port to Watcom was done slightly differently from ours.
Diffstat (limited to 'Utilities/cmlibarchive/libarchive/archive_write.c')
-rw-r--r-- | Utilities/cmlibarchive/libarchive/archive_write.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c index b296069..8997193 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write.c +++ b/Utilities/cmlibarchive/libarchive/archive_write.c @@ -503,8 +503,9 @@ _archive_write_close(struct archive *_a) archive_clear_error(&a->archive); - /* Finish the last entry. */ - if (a->archive.state == ARCHIVE_STATE_DATA) + /* Finish the last entry if a finish callback is specified */ + if (a->archive.state == ARCHIVE_STATE_DATA + && a->format_finish_entry != NULL) r = ((a->format_finish_entry)(a)); /* Finish off the archive. */ @@ -638,6 +639,9 @@ _archive_write_header(struct archive *_a, struct archive_entry *entry) /* Format and write header. */ r2 = ((a->format_write_header)(a, entry)); + if (r2 == ARCHIVE_FAILED) { + return (ARCHIVE_FAILED); + } if (r2 == ARCHIVE_FATAL) { a->archive.state = ARCHIVE_STATE_FATAL; return (ARCHIVE_FATAL); @@ -658,7 +662,8 @@ _archive_write_finish_entry(struct archive *_a) archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, "archive_write_finish_entry"); - if (a->archive.state & ARCHIVE_STATE_DATA) + if (a->archive.state & ARCHIVE_STATE_DATA + && a->format_finish_entry != NULL) ret = (a->format_finish_entry)(a); a->archive.state = ARCHIVE_STATE_HEADER; return (ret); @@ -671,8 +676,13 @@ static ssize_t _archive_write_data(struct archive *_a, const void *buff, size_t s) { struct archive_write *a = (struct archive_write *)_a; + const size_t max_write = INT_MAX; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, ARCHIVE_STATE_DATA, "archive_write_data"); + /* In particular, this catches attempts to pass negative values. */ + if (s > max_write) + s = max_write; archive_clear_error(&a->archive); return ((a->format_write_data)(a, buff, s)); } |