for all length adjustable algorithms (blake2b, sha2, sha3).
[bug introduced in coreutils-9.2]
- 'cksum --check -a sha2' now supports tagged format.
- '-a sha2' is not required with tagged format, but should be accepted.
+ 'cksum --check -a sha2' has better support for tagged format. Previously
+ an unneeded but explicit '-a sha2' did not match standard tags like SHA256.
+ Also non standard SHA2 tags with a bad length resulted in undefined behavior.
[bug introduced in coreutils-9.8]
'rm -d DIR' no longer fails on Ceph snapshot directories.
#include <getopt.h>
#include <sys/types.h>
+#include "assure.h"
#include "system.h"
#include "argmatch.h"
#include "c-ctype.h"
case SHA512_DIGEST_SIZE:
return sha512_stream (stream, resstream);
default:
- unreachable ();
+ affirm (false);
}
}
static int
case SHA3_512_DIGEST_SIZE:
return sha3_512_stream (stream, resstream);
default:
- unreachable ();
+ affirm (false);
}
}
static int
if (xstrtoumax (s + i, &siend, 0, &length, nullptr) != LONGINT_OK)
return false;
# if HASH_ALGO_CKSUM
- else if (cksum_algorithm == sha3)
+ else if (cksum_algorithm == sha2 || cksum_algorithm == sha3)
{
- if (length != SHA3_224_DIGEST_SIZE * 8
- && length != SHA3_256_DIGEST_SIZE * 8
- && length != SHA3_384_DIGEST_SIZE * 8
- && length != SHA3_512_DIGEST_SIZE * 8)
+ if (length != SHA224_DIGEST_SIZE * 8
+ && length != SHA256_DIGEST_SIZE * 8
+ && length != SHA384_DIGEST_SIZE * 8
+ && length != SHA512_DIGEST_SIZE * 8)
return false;
}
# endif
done
done
+# Ensure invalid length is handled appropriately
+# coreutils-9.8 had undefined behavior with the following:
+printf '%s\n' 'SHA2-128 (/dev/null) = 38b060a751ac96384cd9327eb1b1e36a' \
+ > sha2-bad-length.sum || framework_failure_
+returns_ 1 cksum --check sha2-bad-length.sum 2>err || fail=1
+echo 'cksum: sha2-bad-length.sum: no properly formatted checksum lines found' \
+ > experr || framework_failure_
+compare experr err || fail=1
+
+
# Ensure leading whitespace and \ ignored
sed 's/^/ \\/' CHECKSUMS | cksum --strict -c || fail=1