diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-07-11 14:36:39 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-07-11 14:36:39 +0200 |
commit | 3ad3aa6441ebaf817137051de2b74cb6b4379e7f (patch) | |
tree | dbd91fe86a10fac1085a25eca1f4045bfcdf3d8e | |
parent | 298ac9507bb6cb932162f863c7b9623c0a37dedb (diff) | |
download | busybox-w32-3ad3aa6441ebaf817137051de2b74cb6b4379e7f.tar.gz busybox-w32-3ad3aa6441ebaf817137051de2b74cb6b4379e7f.tar.bz2 busybox-w32-3ad3aa6441ebaf817137051de2b74cb6b4379e7f.zip |
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>
-rw-r--r-- | coreutils/md5_sha1_sum.c | 13 | ||||
-rwxr-xr-x | testsuite/sha1sum.tests | 10 |
2 files changed, 18 insertions, 5 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 0e57673f1..b4bdc262c 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
@@ -301,9 +301,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
301 | 301 | ||
302 | count_total++; | 302 | count_total++; |
303 | filename_ptr = strchr(line, ' '); | 303 | filename_ptr = strchr(line, ' '); |
304 | if (filename_ptr == NULL | 304 | if (!filename_ptr) { |
305 | || (filename_ptr[1] != ' ' && filename_ptr[1] != '*') | ||
306 | ) { | ||
307 | if (flags & FLAG_WARN) { | 305 | if (flags & FLAG_WARN) { |
308 | bb_simple_error_msg("invalid format"); | 306 | bb_simple_error_msg("invalid format"); |
309 | } | 307 | } |
@@ -312,8 +310,13 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
312 | free(line); | 310 | free(line); |
313 | continue; | 311 | continue; |
314 | } | 312 | } |
315 | *filename_ptr = '\0'; | 313 | *filename_ptr++ = '\0'; |
316 | filename_ptr += 2; | 314 | /* coreutils 9.1 allows "HASH FILENAME" format, |
315 | * with only one space. Skip the 'correct' | ||
316 | * " " or " *" delimiter if it is there: | ||
317 | */ | ||
318 | if (*filename_ptr == ' ' || *filename_ptr == '*') | ||
319 | filename_ptr++; | ||
317 | 320 | ||
318 | hash_value = hash_file(in_buf, filename_ptr, sha3_width); | 321 | hash_value = hash_file(in_buf, filename_ptr, sha3_width); |
319 | 322 | ||
diff --git a/testsuite/sha1sum.tests b/testsuite/sha1sum.tests index a968fa87c..7ad1334c3 100755 --- a/testsuite/sha1sum.tests +++ b/testsuite/sha1sum.tests | |||
@@ -1,3 +1,13 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | . ./testing.sh | ||
4 | |||
5 | # testing "test name" "cmd" "expected result" "file input" "stdin" | ||
6 | >EMPTY | ||
7 | testing "sha1sum: one-space separated input for -c" \ | ||
8 | 'echo "da39a3ee5e6b4b0d3255bfef95601890afd80709 EMPTY" | sha1sum -c' \ | ||
9 | "EMPTY: OK\n" \ | ||
10 | "" "" | ||
11 | rm EMPTY | ||
12 | |||
3 | . ./md5sum.tests sha1sum d41337e834377140ae7f98460d71d908598ef04f | 13 | . ./md5sum.tests sha1sum d41337e834377140ae7f98460d71d908598ef04f |