From: Paul Eggert Date: Tue, 30 Jul 2024 15:31:45 +0000 (-0700) Subject: Better overflow checking for blocking factor X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=7079fc369b30404fc0b7f292716033b4a41c478e;p=thirdparty%2Ftar.git 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. --- diff --git a/src/tar.c b/src/tar.c index 0c31f156..8efa3794 100644 --- 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"))); }