diff --git a/NEWS b/NEWS index 1d300fcf0..46c724579 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,12 @@ GNU coreutils NEWS -*- outline -*- was used, even when the look-up inside the chroot succeeded. [bug introduced in coreutils-8.23] + 'cksum' now detects GNU and BSD reversed formats for each checksum file. + Previously mixing these formats across files could reject valid checksums + or incorrectly interpret a space as part of a file name. + This also applies to the md5sum, sha*sum, and b2sum utilities. + [bug introduced in coreutils-8.14] + 'cksum --check' now rejects length suffixes on fixed-length algorithm tags, such as SHA256-8. Previously these caused only part of the digest to be checked, and could cause subsequent full-length untagged checksums to be diff --git a/src/cksum.c b/src/cksum.c index 41f146a87..f5e560243 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -1397,6 +1397,7 @@ digest_check (char const *checkfile_name) } } + bsd_reversed = -1; line_number = 0; line = NULL; line_chars_allocated = 0; diff --git a/tests/cksum/cksum-c.sh b/tests/cksum/cksum-c.sh index 1a1c2a7b4..5a7d8eb87 100755 --- a/tests/cksum/cksum-c.sh +++ b/tests/cksum/cksum-c.sh @@ -22,6 +22,12 @@ uses_strace_ shuf -i 1-10 > input || framework_failure_ +# Detect GNU and BSD reversed formats independently for each checksum file. +cksum -a sha256 --untagged input > standard.sum || framework_failure_ +sed 's/ input$/ input/' standard.sum > reversed.sum || framework_failure_ +cksum -a sha256 --strict --check standard.sum reversed.sum || fail=1 +cksum -a sha256 --strict --check reversed.sum standard.sum || fail=1 + for args in '-a sha2 -l 384' '-a blake2b' '-a blake2b -l 384' '-a sm3'; do cksum $args 'input' >> CHECKSUMS || fail=1 done diff --git a/tests/cksum/md5sum-bsd.sh b/tests/cksum/md5sum-bsd.sh index 7859fbbf5..98f167bfd 100755 --- a/tests/cksum/md5sum-bsd.sh +++ b/tests/cksum/md5sum-bsd.sh @@ -32,10 +32,14 @@ for i in 'a' ' b' '*c' 'dd' ' '; do done sed 's/ / /' check.md5sum > check.md5 -# Note only a single format is supported per run +# Note only a single untagged format is supported per checksum file. md5sum --strict -c check.md5sum || fail=1 md5sum --strict -c check.md5 || fail=1 +# The format of one checksum file must not affect parsing of the next. +md5sum --strict -c check.md5sum check.md5 || fail=1 +md5sum --strict -c check.md5 check.md5sum || fail=1 + # Ensure we don't trigger BSD reversed format with GPG headers etc. { echo '____not_all_hex_so_no_match_____ blah'; cat check.md5sum; } > check2.md5sum || framework_failure_