]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: fix --check with non tagged format checksums
authorPádraig Brady <P@draigBrady.com>
Thu, 16 Sep 2021 10:40:51 +0000 (11:40 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 16 Sep 2021 11:20:24 +0000 (12:20 +0100)
* src/digest.c: Always set the digest_length, so that
we check the correct number of hex digits when parsing
non tagged format checksums.
* tests/misc/cksum-a.sh: Add a test case.  Also fix
up this test which was ineffective due to fail=1
being set in a subshell and ignored.

src/digest.c
tests/misc/cksum-a.sh

index fdf01b21b9f07a9dee7022484a1b7746eee1c36d..9ee37a104000aeca350b273f18af60129223f140 100644 (file)
@@ -1370,7 +1370,7 @@ main (int argc, char **argv)
            quote (DIGEST_TYPE_STRING),
            BLAKE2B_MAX_LEN * 8);
     }
-  if (digest_length == 0 && ! do_check)
+  if (digest_length == 0)
     {
 # if HASH_ALGO_BLAKE2
       digest_length = BLAKE2B_MAX_LEN * 8;
index d6d50ccee447effe85a83a419b95d52b44b4e1bc..92d84203d3229ad2019b4d361de6f0515c9d25aa 100755 (executable)
@@ -19,7 +19,7 @@
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ cksum
 
-printf "
+cat > input_options <<\EOF || framework_failure_
 bsd     sum -r
 sysv    sum -s
 crc     cksum
@@ -30,10 +30,21 @@ sha256  sha256sum -t
 sha384  sha384sum -t
 sha512  sha512sum -t
 blake2b b2sum -t
-" | while read algo prog; do
-  $prog < /dev/null >> out || continue
-  cksum --untagged --algorithm=$algo < /dev/null >> out-a || fail=1
-done
+EOF
+
+while read algo prog; do
+  $prog /dev/null >> out || continue
+  cksum --untagged --algorithm=$algo /dev/null > out-c || fail=1
+
+  case "$algo" in
+    bsd) ;;
+    sysv) ;;
+    crc) ;;
+    *) cksum --check --algorithm=$algo out-c || fail=1 ;;
+  esac
+
+  cat out-c >> out-a || framework_failure_
+done < input_options
 compare out out-a || fail=1
 
 returns_ 1 cksum -a bsd --tag </dev/null