From: Martin Matuska Date: Thu, 4 Apr 2019 22:21:32 +0000 (+0200) Subject: Fix handling of strtol() and strtoul() X-Git-Tag: v3.4.0~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0297127fd8374fe780b929b91a66d0c209dfc8ff;p=thirdparty%2Flibarchive.git Fix handling of strtol() and strtoul() Fixes #1168 --- diff --git a/libarchive/archive_read_support_format_warc.c b/libarchive/archive_read_support_format_warc.c index e8fc8428b..c1c54450c 100644 --- a/libarchive/archive_read_support_format_warc.c +++ b/libarchive/archive_read_support_format_warc.c @@ -744,8 +744,9 @@ _warc_rdlen(const char *buf, size_t bsz) /* there must be at least one digit */ if (!isdigit((unsigned char)*val)) return -1; + errno = 0; len = strtol(val, &on, 10); - if (on != eol) { + if (errno != 0 || on != eol) { /* line must end here */ return -1; } diff --git a/libarchive/archive_write_add_filter_xz.c b/libarchive/archive_write_add_filter_xz.c index b0f25a6ef..0f7c8cfc3 100644 --- a/libarchive/archive_write_add_filter_xz.c +++ b/libarchive/archive_write_add_filter_xz.c @@ -390,10 +390,13 @@ archive_compressor_xz_options(struct archive_write_filter *f, data->compression_level = 6; return (ARCHIVE_OK); } else if (strcmp(key, "threads") == 0) { + char *endptr; + if (value == NULL) return (ARCHIVE_WARN); - data->threads = (int)strtoul(value, NULL, 10); - if (data->threads == 0 && errno != 0) { + errno = 0; + data->threads = (int)strtoul(value, &endptr, 10); + if (errno != 0 || *endptr != '\0') { data->threads = 1; return (ARCHIVE_WARN); } diff --git a/libarchive/archive_write_set_format_xar.c b/libarchive/archive_write_set_format_xar.c index 36d4a615e..5e4b90e06 100644 --- a/libarchive/archive_write_set_format_xar.c +++ b/libarchive/archive_write_set_format_xar.c @@ -496,10 +496,13 @@ xar_options(struct archive_write *a, const char *key, const char *value) return (ARCHIVE_OK); } if (strcmp(key, "threads") == 0) { + char *endptr; + if (value == NULL) return (ARCHIVE_FAILED); - xar->opt_threads = (int)strtoul(value, NULL, 10); - if (xar->opt_threads == 0 && errno != 0) { + errno = 0; + xar->opt_threads = (int)strtoul(value, &endptr, 10); + if (errno != 0 || *endptr != '\0') { xar->opt_threads = 1; archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,