]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
b2sum: fix UAR with --check with malformed checksum lines
authorPádraig Brady <P@draigBrady.com>
Thu, 22 Jun 2023 20:33:58 +0000 (21:33 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 22 Jun 2023 22:22:07 +0000 (23:22 +0100)
* src/digest.c (split_3): Reinstate the check for whitespace after the
digest portion of the line, so that we exit early before inspecting
the file name which would be outside the passed buffer in the case
where the input does not contain a newline.
* tests/cksum/b2sum.sh: Add a test case.
* NEWS: Mention the bug fix.
* THANKS.in: Add Frank Busse who has reported multiple bugs using KLEE.
Fixes https://bugs.gnu.org/64229

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

diff --git a/NEWS b/NEWS
index 3e2280777ca229b38c4628f55831d784bf3a673c..3c134db52b329cfdf8f7f990397c9a8631b9b048 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   fail on files with inode numbers that do not fit into 32 bits.
   [This bug was present in "the beginning".]
 
+  'b2sum --check' will no longer read unallocated memory when
+  presented with malformed checksum lines.
+  [bug introduced in coreutils-9.2]
+
   'cp --parents' again succeeds when preserving mode for absolute directories.
   Previously it would have failed with a "No such file or directory" error.
   [bug introduced in coreutils-9.1]
index 8d903268e0a7b31c66b541e4adf3883649ea3b18..6079029a9b4b41ad3268ae76c405456ec67fdc98 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
@@ -211,6 +211,7 @@ Francesco Montorsi                  fr_m@hotmail.com
 François Pinard                     pinard@iro.umontreal.ca
 François Rigault                    rigault.francois@gmail.com
 Frank Adler                         fadler@allesklar.de
+Frank Busse                         f.busse@imperial.ac.uk
 Frank T Lofaro                      ftlofaro@snooks.Egr.UNLV.EDU
 Fred Fish                           fnf@ninemoons.com
 Frédéric L. W. Meunier              0@pervalidus.net
index ab32968db7326ca281addd852ca4cb931df0ab99..851c7d118812cb117ddbf482ee1b650c1a1d59a8 100644 (file)
@@ -862,6 +862,10 @@ split_3 (char *s, size_t s_len,
   while (s[i] && !ISWHITE (s[i]))
     i++;
 
+  /* The digest must be followed by at least one whitespace character.  */
+  if (i == s_len)
+    return false;
+
   *d_len = &s[i] - (char *) *digest;
   s[i++] = '\0';
 
index 6a2d130246443c4b418cbb7d9661d381a38ab70a..7013b4972c3c6c2f64be8cee37d57b22a18b060c 100755 (executable)
@@ -61,6 +61,11 @@ printf '%s\n' 'BLAKE2' 'BLAKE2b' 'BLAKE2-' 'BLAKE2(' 'BLAKE2 (' > crash.check \
   || framework_failure_
 returns_ 1 $prog -c crash.check || fail=1
 
+# This would read unallocated memory from coreutils-9.2 to coreutils-9.3
+# which would trigger with ASAN or valgrind
+printf '0A0BA0' > overflow.check || framework_failure_
+returns_ 1 $prog -c overflow.check || fail=1
+
 done
 
 Exit $fail