diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-07-11 19:51:08 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-07-11 19:51:08 +0200 |
| commit | b0056ea86d427d76bb4c08506198d0c97075fdf6 (patch) | |
| tree | a0e17ebc3c96790755ad9342bb3c1bd78e8425f5 | |
| parent | f6348e50ef2a2c28c611df4df92207d7b378e78e (diff) | |
| download | busybox-w32-b0056ea86d427d76bb4c08506198d0c97075fdf6.tar.gz busybox-w32-b0056ea86d427d76bb4c08506198d0c97075fdf6.tar.bz2 busybox-w32-b0056ea86d427d76bb4c08506198d0c97075fdf6.zip | |
{md5,shaN}sum: make -c EMPTY fail
function old new delta
md5_sha1_sum_main 466 485 +19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | coreutils/md5_sha1_sum.c | 23 | ||||
| -rwxr-xr-x | testsuite/md5sum.tests | 22 |
2 files changed, 31 insertions, 14 deletions
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c index 1a5342e87..c0e816ba6 100644 --- a/coreutils/md5_sha1_sum.c +++ b/coreutils/md5_sha1_sum.c | |||
| @@ -66,6 +66,10 @@ | |||
| 66 | //usage: "\n -w Warn about improperly formatted checksum lines" | 66 | //usage: "\n -w Warn about improperly formatted checksum lines" |
| 67 | //usage: ) | 67 | //usage: ) |
| 68 | 68 | ||
| 69 | //FIXME: GNU coreutils 8.25 has no -s option, it has only these two long opts: | ||
| 70 | // --quiet don't print OK for each successfully verified file | ||
| 71 | // --status don't output anything, status code shows success | ||
| 72 | |||
| 69 | #include "libbb.h" | 73 | #include "libbb.h" |
| 70 | 74 | ||
| 71 | /* This is a NOEXEC applet. Be very careful! */ | 75 | /* This is a NOEXEC applet. Be very careful! */ |
| @@ -174,6 +178,8 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
| 174 | unsigned flags; | 178 | unsigned flags; |
| 175 | 179 | ||
| 176 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { | 180 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) { |
| 181 | /* -s and -w require -c */ | ||
| 182 | opt_complementary = "s?c:w?c"; | ||
| 177 | /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ | 183 | /* -b "binary", -t "text" are ignored (shaNNNsum compat) */ |
| 178 | flags = getopt32(argv, "scwbt"); | 184 | flags = getopt32(argv, "scwbt"); |
| 179 | argv += optind; | 185 | argv += optind; |
| @@ -185,15 +191,6 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
| 185 | if (!*argv) | 191 | if (!*argv) |
| 186 | *--argv = (char*)"-"; | 192 | *--argv = (char*)"-"; |
| 187 | 193 | ||
| 188 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) { | ||
| 189 | if (flags & FLAG_SILENT) { | ||
| 190 | bb_error_msg_and_die("-%c is meaningful only with -c", 's'); | ||
| 191 | } | ||
| 192 | if (flags & FLAG_WARN) { | ||
| 193 | bb_error_msg_and_die("-%c is meaningful only with -c", 'w'); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | do { | 194 | do { |
| 198 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) { | 195 | if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) { |
| 199 | FILE *pre_computed_stream; | 196 | FILE *pre_computed_stream; |
| @@ -244,6 +241,14 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv) | |||
| 244 | bb_error_msg("WARNING: %d of %d computed checksums did NOT match", | 241 | bb_error_msg("WARNING: %d of %d computed checksums did NOT match", |
| 245 | count_failed, count_total); | 242 | count_failed, count_total); |
| 246 | } | 243 | } |
| 244 | if (count_total == 0) { | ||
| 245 | return_value = EXIT_FAILURE; | ||
| 246 | /* | ||
| 247 | * md5sum from GNU coreutils 8.25 says: | ||
| 248 | * md5sum: <FILE>: no properly formatted MD5 checksum lines found | ||
| 249 | */ | ||
| 250 | bb_error_msg("%s: no checksum lines found", *argv); | ||
| 251 | } | ||
| 247 | fclose_if_not_stdin(pre_computed_stream); | 252 | fclose_if_not_stdin(pre_computed_stream); |
| 248 | } else { | 253 | } else { |
| 249 | uint8_t *hash_value = hash_file(*argv); | 254 | uint8_t *hash_value = hash_file(*argv); |
diff --git a/testsuite/md5sum.tests b/testsuite/md5sum.tests index 6c75b6d1c..cca26dc64 100755 --- a/testsuite/md5sum.tests +++ b/testsuite/md5sum.tests | |||
| @@ -23,6 +23,8 @@ test -f "$bindir/.config" && . "$bindir/.config" | |||
| 23 | test x"$CONFIG_FEATURE_FANCY_HEAD" != x"y" \ | 23 | test x"$CONFIG_FEATURE_FANCY_HEAD" != x"y" \ |
| 24 | && { echo "SKIPPED: $sum"; exit 0; } | 24 | && { echo "SKIPPED: $sum"; exit 0; } |
| 25 | 25 | ||
| 26 | FAILCOUNT=0 | ||
| 27 | |||
| 26 | text="The quick brown fox jumps over the lazy dog" | 28 | text="The quick brown fox jumps over the lazy dog" |
| 27 | text=`yes "$text" | head -c 9999` | 29 | text=`yes "$text" | head -c 9999` |
| 28 | 30 | ||
| @@ -33,11 +35,21 @@ while test $n -le 999; do | |||
| 33 | n=$(($n+1)) | 35 | n=$(($n+1)) |
| 34 | done | "$sum" | 36 | done | "$sum" |
| 35 | )` | 37 | )` |
| 36 | 38 | if test x"$result" != x"$expected -"; then | |
| 37 | if test x"$result" = x"$expected -"; then | 39 | echo "FAIL: $sum (r:$result exp:$expected)" |
| 40 | : $((FAILCOUNT++)) | ||
| 41 | else | ||
| 38 | echo "PASS: $sum" | 42 | echo "PASS: $sum" |
| 39 | exit 0 | ||
| 40 | fi | 43 | fi |
| 41 | 44 | ||
| 42 | echo "FAIL: $sum (r:$result exp:$expected)" | 45 | # GNU compat: -c EMPTY must fail (exitcode 1)! |
| 43 | exit 1 | 46 | >EMPTY |
| 47 | if "$sum" -c EMPTY 2>/dev/null; then | ||
| 48 | echo "FAIL: $sum -c EMPTY" | ||
| 49 | : $((FAILCOUNT++)) | ||
| 50 | else | ||
| 51 | echo "PASS: $sum -c EMPTY" | ||
| 52 | fi | ||
| 53 | rm EMPTY | ||
| 54 | |||
| 55 | exit $FAILCOUNT | ||
