From 73f8fd760d4c5e63e6290c65092063e855e68626 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Thu, 16 Sep 2021 11:40:51 +0100 Subject: [PATCH] cksum: fix --check with non tagged format checksums * 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 | 2 +- tests/misc/cksum-a.sh | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/digest.c b/src/digest.c index fdf01b21b9..9ee37a1040 100644 --- a/src/digest.c +++ b/src/digest.c @@ -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; diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh index d6d50ccee4..92d84203d3 100755 --- a/tests/misc/cksum-a.sh +++ b/tests/misc/cksum-a.sh @@ -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