From: Paul Eggert Date: Sun, 11 Aug 2024 01:24:15 +0000 (-0700) Subject: digest: improve -l overflow diagnostic X-Git-Tag: v9.6~192 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2c84fe630fe930f60bce3d0c632196903d64441;p=thirdparty%2Fcoreutils.git 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. --- 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