aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-07-11 19:51:08 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-07-11 19:51:08 +0200
commitb0056ea86d427d76bb4c08506198d0c97075fdf6 (patch)
treea0e17ebc3c96790755ad9342bb3c1bd78e8425f5
parentf6348e50ef2a2c28c611df4df92207d7b378e78e (diff)
downloadbusybox-b0056ea86d427d76bb4c08506198d0c97075fdf6.tar.gz
{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.c23
-rwxr-xr-xtestsuite/md5sum.tests22
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 @@
//usage: "\n -w Warn about improperly formatted checksum lines"
//usage: )
+//FIXME: GNU coreutils 8.25 has no -s option, it has only these two long opts:
+// --quiet don't print OK for each successfully verified file
+// --status don't output anything, status code shows success
+
#include "libbb.h"
/* This is a NOEXEC applet. Be very careful! */
@@ -174,6 +178,8 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
unsigned flags;
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
+ /* -s and -w require -c */
+ opt_complementary = "s?c:w?c";
/* -b "binary", -t "text" are ignored (shaNNNsum compat) */
flags = getopt32(argv, "scwbt");
argv += optind;
@@ -185,15 +191,6 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
if (!*argv)
*--argv = (char*)"-";
- if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) {
- if (flags & FLAG_SILENT) {
- bb_error_msg_and_die("-%c is meaningful only with -c", 's');
- }
- if (flags & FLAG_WARN) {
- bb_error_msg_and_die("-%c is meaningful only with -c", 'w');
- }
- }
-
do {
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && (flags & FLAG_CHECK)) {
FILE *pre_computed_stream;
@@ -244,6 +241,14 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
bb_error_msg("WARNING: %d of %d computed checksums did NOT match",
count_failed, count_total);
}
+ if (count_total == 0) {
+ return_value = EXIT_FAILURE;
+ /*
+ * md5sum from GNU coreutils 8.25 says:
+ * md5sum: <FILE>: no properly formatted MD5 checksum lines found
+ */
+ bb_error_msg("%s: no checksum lines found", *argv);
+ }
fclose_if_not_stdin(pre_computed_stream);
} else {
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"
test x"$CONFIG_FEATURE_FANCY_HEAD" != x"y" \
&& { echo "SKIPPED: $sum"; exit 0; }
+FAILCOUNT=0
+
text="The quick brown fox jumps over the lazy dog"
text=`yes "$text" | head -c 9999`
@@ -33,11 +35,21 @@ while test $n -le 999; do
n=$(($n+1))
done | "$sum"
)`
-
-if test x"$result" = x"$expected -"; then
+if test x"$result" != x"$expected -"; then
+ echo "FAIL: $sum (r:$result exp:$expected)"
+ : $((FAILCOUNT++))
+else
echo "PASS: $sum"
- exit 0
fi
-echo "FAIL: $sum (r:$result exp:$expected)"
-exit 1
+# GNU compat: -c EMPTY must fail (exitcode 1)!
+>EMPTY
+if "$sum" -c EMPTY 2>/dev/null; then
+ echo "FAIL: $sum -c EMPTY"
+ : $((FAILCOUNT++))
+else
+ echo "PASS: $sum -c EMPTY"
+fi
+rm EMPTY
+
+exit $FAILCOUNT