From f2c84fe630fe930f60bce3d0c632196903d64441 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 10 Aug 2024 18:24:15 -0700 Subject: [PATCH] digest: improve -l overflow diagnostic * src/digest.c (main): Use better diagnostic for -l overflow, by using XTOINT_MAX_QUIET to suppress the worse diagnostic. --- src/digest.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/digest.c b/src/digest.c index 1a4cfd1fbf..821e961396 100644 --- a/src/digest.c +++ b/src/digest.c @@ -1394,8 +1394,9 @@ main (int argc, char **argv) #endif #if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM case 'l': - digest_length = xdectoumax (optarg, 0, UINTMAX_MAX, "", - _("invalid length"), 0); + digest_length = xnumtoumax (optarg, 10, 0, BLAKE2B_MAX_LEN * 8, "", + _("invalid length"), 0, + XTOINT_MAX_QUIET); digest_length_str = optarg; break; #endif @@ -1473,11 +1474,6 @@ main (int argc, char **argv) error (EXIT_FAILURE, 0, _("--length is only supported with --algorithm=blake2b")); # endif - if (digest_length % 8 != 0) - { - error (0, 0, _("invalid length: %s"), quote (digest_length_str)); - error (EXIT_FAILURE, 0, _("length is not a multiple of 8")); - } if (digest_length > BLAKE2B_MAX_LEN * 8) { error (0, 0, _("invalid length: %s"), quote (digest_length_str)); @@ -1486,6 +1482,11 @@ main (int argc, char **argv) quote (DIGEST_TYPE_STRING), BLAKE2B_MAX_LEN * 8); } + if (digest_length % 8 != 0) + { + error (0, 0, _("invalid length: %s"), quote (digest_length_str)); + error (EXIT_FAILURE, 0, _("length is not a multiple of 8")); + } if (digest_length == 0) { # if HASH_ALGO_BLAKE2 -- 2.47.2