shaNNNsum: accept one-space "HASH FILENAME" format for -c, closes 14866

function                                             old     new   delta
md5_sha1_sum_main                                    496     501      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2022-07-11 14:36:39 +02:00
parent 298ac9507b
commit 3ad3aa6441
2 changed files with 18 additions and 5 deletions

View File

@ -301,9 +301,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
count_total++; count_total++;
filename_ptr = strchr(line, ' '); filename_ptr = strchr(line, ' ');
if (filename_ptr == NULL if (!filename_ptr) {
|| (filename_ptr[1] != ' ' && filename_ptr[1] != '*')
) {
if (flags & FLAG_WARN) { if (flags & FLAG_WARN) {
bb_simple_error_msg("invalid format"); bb_simple_error_msg("invalid format");
} }
@ -312,8 +310,13 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
free(line); free(line);
continue; continue;
} }
*filename_ptr = '\0'; *filename_ptr++ = '\0';
filename_ptr += 2; /* coreutils 9.1 allows "HASH FILENAME" format,
* with only one space. Skip the 'correct'
* " " or " *" delimiter if it is there:
*/
if (*filename_ptr == ' ' || *filename_ptr == '*')
filename_ptr++;
hash_value = hash_file(in_buf, filename_ptr, sha3_width); hash_value = hash_file(in_buf, filename_ptr, sha3_width);

View File

@ -1,3 +1,13 @@
#!/bin/sh #!/bin/sh
. ./testing.sh
# testing "test name" "cmd" "expected result" "file input" "stdin"
>EMPTY
testing "sha1sum: one-space separated input for -c" \
'echo "da39a3ee5e6b4b0d3255bfef95601890afd80709 EMPTY" | sha1sum -c' \
"EMPTY: OK\n" \
"" ""
rm EMPTY
. ./md5sum.tests sha1sum d41337e834377140ae7f98460d71d908598ef04f . ./md5sum.tests sha1sum d41337e834377140ae7f98460d71d908598ef04f