]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
libarchive/7zip: Properly check strto* errno value
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 16 Mar 2026 14:57:17 +0000 (15:57 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 16 Mar 2026 14:57:17 +0000 (15:57 +0100)
Set errno to 0 before calling strtoimax/strtol and check its value
afterwards.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libarchive/archive_write_set_format_7zip.c

index ebdb16e9022ae172d56e6402d7d367bc06626f15..3105cf6b2954bc8e10a4a8c52920b64180daa200 100644 (file)
@@ -333,6 +333,7 @@ string_to_number(const char *string, intmax_t *numberp)
 
        if (string == NULL || *string == '\0')
                return (ARCHIVE_WARN);
+       errno = 0;
        *numberp = strtoimax(string, &end, 10);
        if (end == string || *end != '\0' || errno == EOVERFLOW) {
                *numberp = 0;
@@ -487,8 +488,9 @@ _7z_options(struct archive_write *a, const char *key, const char *value)
                }
 
                char *end = NULL;
+               errno = 0;
                long lvl = strtol(value, &end, 10);
-               if (end == NULL || *end != '\0') {
+               if (errno != 0 || end == NULL || *end != '\0') {
                        archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
                                "parsing compression-level option value failed `%s'", value);
                        return (ARCHIVE_FAILED);