Better overflow checking for blocking factor

* src/tar.c (parse_opt): Use ckd_add and ckd_mul instead of
less-obvious code that relies on implementation-defined
conversions.
This commit is contained in:
Paul Eggert
2024-07-30 08:31:45 -07:00
parent b26e798a0f
commit 7079fc369b

View File

@@ -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")));
}