From 7079fc369b30404fc0b7f292716033b4a41c478e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 30 Jul 2024 08:31:45 -0700 Subject: [PATCH] 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. --- src/tar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"))); } -- 2.47.2