]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
b2sum: --length: fix upper bound check
authorPádraig Brady <P@draigBrady.com>
Sat, 30 Aug 2025 11:08:24 +0000 (12:08 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 30 Aug 2025 11:44:29 +0000 (12:44 +0100)
* src/digest.c (main): Don't saturate -l to BLAKE2B_MAX_LEN,
so that the subsequent bounds check is performed.
* tests/cksum/b2sum.sh: Add a test case.
* NEWS: Mention the fix introduced in commit v9.5-71-gf2c84fe63

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

diff --git a/NEWS b/NEWS
index f2e7c9e6ee5b0e0822b150c81346fd32f7c2eb50..988cb96a889c9e60a09ef1ffb17aeb7614508732 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  'b2sum' will diagnose --length values that are too big.
+  Previously it would have silently assumed 512 for any larger values.
+  [bug introduced in coreutils-9.6]
+
   'basenc -d -i' will now strip '=' characters from the input
   in encodings where padding characters are not valid.
   [bug introduced with the basenc program in coreutils-8.31]
index 302739e9f511e6796678b698414266dfbe8ec534..0e4e62dee7b5fbe555641a361412418656f8203f 100644 (file)
@@ -1402,7 +1402,7 @@ main (int argc, char **argv)
 #endif
 #if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
       case 'l':
-        digest_length = xnumtoumax (optarg, 10, 0, BLAKE2B_MAX_LEN * 8, "",
+        digest_length = xnumtoumax (optarg, 10, 0, UINTMAX_MAX, "",
                                     _("invalid length"), 0,
                                     XTOINT_MAX_QUIET);
         digest_length_str = optarg;
index af3ead798a4c48cddceca8a86a1787a636f4a02a..731ddb38c79d2fd38b35f61c67befa753225d0d6 100755 (executable)
@@ -18,6 +18,7 @@
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ cksum
+getlimits_
 
 for prog in 'b2sum' 'cksum -a blake2b'; do
 # Also check b2sum if built
@@ -69,6 +70,17 @@ returns_ 1 $prog -c overflow.check || fail=1
 # Only validate the last specified, used length
 $prog -l 123 -l 128 /dev/null || fail=1
 
+# This would not flag an error in coreutils 9.6 and 9.7
+for len in 513 1024 $UINTMAX_OFLOW; do
+  returns_ 1 $prog -l $len /dev/null 2>err || fail=1
+  progname=$(echo "$prog" | cut -f1 -d' ')
+  cat <<EOF > exp || framework_failure_
+$progname: invalid length: '$len'
+$progname: maximum digest length for 'BLAKE2b' is 512 bits
+EOF
+  compare exp err || fail=1
+done
+
 done
 
 Exit $fail