summaryrefslogtreecommitdiffstats
path: root/Utilities/cmlibarchive/libarchive/archive_write.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-04-24 19:31:45 (GMT)
committerBrad King <brad.king@kitware.com>2014-04-24 19:31:45 (GMT)
commitaaa6c8a6cefff2fc8938453f09fb91523b9e87e4 (patch)
treefd186e3ee9ba0c4d514baa27d78b8553bcedcb70 /Utilities/cmlibarchive/libarchive/archive_write.c
parentfaf291a9c41cc2a4ffa6797c1d35c7863118a4c4 (diff)
parentd64ee80d6bfb97a63953796074e792f4883e5fb2 (diff)
downloadCMake-aaa6c8a6cefff2fc8938453f09fb91523b9e87e4.zip
CMake-aaa6c8a6cefff2fc8938453f09fb91523b9e87e4.tar.gz
CMake-aaa6c8a6cefff2fc8938453f09fb91523b9e87e4.tar.bz2
Merge branch 'master' into doc-singlehtml
Resolve conflicts in Utilities/Sphinx/CMakeLists.txt by adding the help options from both sides.
Diffstat (limited to 'Utilities/cmlibarchive/libarchive/archive_write.c')
-rw-r--r--Utilities/cmlibarchive/libarchive/archive_write.c16
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));
}