]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: consistently validate --length attributes
authorPádraig Brady <P@draigBrady.com>
Mon, 4 Mar 2024 16:33:23 +0000 (16:33 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 4 Mar 2024 16:35:27 +0000 (16:35 +0000)
* src/digest.c (main): Only validate the last used --length
for being a multiple of 8.
* tests/cksum/b2sum.sh: Add a test case.
Fixes https://bugs.gnu.org/69546

src/digest.c
tests/cksum/b2sum.sh

index 0d82eb6b41fe995ff743a94f217d8116723f4d96..96b811b6c8d987e231ec531a81a15c44d5155061 100644 (file)
@@ -1397,11 +1397,6 @@ main (int argc, char **argv)
         digest_length = xdectoumax (optarg, 0, UINTMAX_MAX, "",
                                 _("invalid length"), 0);
         digest_length_str = optarg;
-        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"));
-          }
         break;
 #endif
 #if !HASH_ALGO_SUM
@@ -1476,6 +1471,11 @@ 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));
index cc480a478e20fadde0bb1aeab10c668e7f5346db..43a62d2fbdc43f89a1ea8c834858a7725c3da5cf 100755 (executable)
@@ -65,6 +65,10 @@ returns_ 1 $prog -c crash.check || fail=1
 printf '0A0BA0' > overflow.check || framework_failure_
 returns_ 1 $prog -c overflow.check || fail=1
 
+# This would fail before coreutil-9.4
+# Only validate the last specified, used length
+$prog -l 123 -l 128 /dev/null || fail=1
+
 done
 
 Exit $fail