]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Better overflow checking for blocking factor
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 30 Jul 2024 15:31:45 +0000 (08:31 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 4 Aug 2024 08:41:43 +0000 (01:41 -0700)
* src/tar.c (parse_opt): Use ckd_add and ckd_mul instead of
less-obvious code that relies on implementation-defined
conversions.

src/tar.c

index 0c31f15676d4adcb01878e3e5b58fa25c71e2367..8efa379434d0ddeb36d56f531b160428d0cb3ebf 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -1501,9 +1501,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
       {
        uintmax_t u;
        if (! (xstrtoumax (arg, 0, 10, &u, "") == LONGINT_OK
-              && u == (blocking_factor = u)
+              && !ckd_add (&blocking_factor, u, 0)
               && 0 < blocking_factor
-              && u == (record_size = u * BLOCKSIZE) / BLOCKSIZE))
+              && !ckd_mul (&record_size, u, BLOCKSIZE)))
          USAGE_ERROR ((0, 0, "%s: %s", quotearg_colon (arg),
                        _("Invalid blocking factor")));
       }