From f13f2d6815e341fe502a7a299e8c825837de3e4c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 2 Aug 2024 23:33:50 -0700 Subject: [PATCH] Parse level options more reliably MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/tar.c (parse_opt): Don’t mishandle out-of-range LEVEL_OPTION. --- src/tar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tar.c b/src/tar.c index 95ba25fc..4d592caf 100644 --- a/src/tar.c +++ b/src/tar.c @@ -1711,9 +1711,9 @@ parse_opt (int key, char *arg, struct argp_state *state) case LEVEL_OPTION: { - char *p; - incremental_level = strtoul (arg, &p, 10); - if (*p) + uintmax_t u; + if (! (xstrtoumax (arg, nullptr, 10, &u, "") == LONGINT_OK + && ckd_add (&incremental_level, u, 0))) USAGE_ERROR ((0, 0, _("Invalid incremental level value"))); } break; @@ -2595,7 +2595,7 @@ decode_options (int argc, char **argv) memset (&newer_mtime_option, 0, sizeof (newer_mtime_option)); } - if (incremental_level != -1 && !listed_incremental_option) + if (0 <= incremental_level && !listed_incremental_option) WARN ((0, 0, _("--level is meaningless without --listed-incremental"))); -- 2.47.2