]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
digest: improve -l overflow diagnostic
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 11 Aug 2024 01:24:15 +0000 (18:24 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 11 Aug 2024 02:30:01 +0000 (19:30 -0700)
* src/digest.c (main): Use better diagnostic for -l overflow,
by using XTOINT_MAX_QUIET to suppress the worse diagnostic.

src/digest.c

index 1a4cfd1fbfead794ea673d7cfd0ae02ec9b3006b..821e9613966cb48138398ef847617db398e2b296 100644 (file)
@@ -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