]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Parse level options more reliably
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Aug 2024 06:33:50 +0000 (23:33 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Aug 2024 08:41:43 +0000 (01:41 -0700)
* src/tar.c (parse_opt): Don’t mishandle out-of-range LEVEL_OPTION.

src/tar.c

index 95ba25fc5825a09d0b9ecf7e4030cdaef19b0377..4d592caf74814d7364c470f7c25dc1a049459a75 100644 (file)
--- 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")));