b2sum: fix crash with --check and truncated input

* src/md5sum.c (split_3): Ensure we don't walk off
the end of the string.
* tests/misc/b2sum.sh: Add test cases.
Fixes https://bugs.gnu.org/28860
This commit is contained in:
Pádraig Brady committed 2017-10-23 23:17:17 -07:00
1 parent f926f7ce0e
commit cc19f63be3
3 files changed
+10 -1

No files matched your search

+3
View File
@@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*-
** Bug fixes
b2sum no longer crashes when processing certain truncated check files.
[bug introduced with b2sum coreutils-8.26]
ptx -S no longer infloops for a pattern which returns zero-length matches.
[the bug dates back to the initial implementation]
+2 -1
View File
@@ -430,7 +430,8 @@ split_3 (char *s, size_t s_len,
#if HASH_ALGO_BLAKE2
/* Terminate and match algorithm name. */
char const *algo_name = &s[i - algo_name_len];
while (! ISWHITE (s[i]) && s[i] != '-' && s[i] != '(')
/* Skip algorithm variants. */
while (s[i] && ! ISWHITE (s[i]) && s[i] != '-' && s[i] != '(')
++i;
bool length_specified = s[i] == '-';
bool openssl_format = s[i] == '('; /* and no length_specified */
+5
View File
@@ -46,4 +46,9 @@ b2sum -l 128 check.vals > out || fail=1
printf '%s\n' '796485dd32fe9b754ea5fd6c721271d9 check.vals' > exp
compare exp out || fail=1
# This would segfault from coreutils-8.26 to coreutils-8.28
printf '%s\n' 'BLAKE2' 'BLAKE2b' 'BLAKE2-' 'BLAKE2(' 'BLAKE2 (' > crash.check \
|| framework_failure_
returns_ 1 b2sum -c crash.check || fail=1
Exit $fail