[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] md5sum: error out on -c empty file
From: Lauri Kasanen <curaga () operamail ! com>
Date: 2016-06-25 17:48:09
Message-ID: 1466876889.2366066.648329745.3269ABA6 () webmail ! messagingengine ! com
[Download RAW message or body]
Hi,
GNU md5sum errors out when passed an empty file via -c. Add a test and
make bb md5sum do the same.
- Lauri
--
http://www.fastmail.com - Choose from over 50 domains or use your own
["0001-md5sum-Add-a-test-for-c-with-empty-file.patch" (0001-md5sum-Add-a-test-for-c-with-empty-file.patch)]
From f5a686ea2ac56d91f6cecf16b234b43608a51ec7 Mon Sep 17 00:00:00 2001
From: Lauri Kasanen <curaga@operamail.com>
Date: Sat, 25 Jun 2016 20:41:03 +0300
Subject: [PATCH 1/2] md5sum: Add a test for -c with empty file
Signed-off-by: Lauri Kasanen <curaga@operamail.com>
---
testsuite/md5sum/md5sum-c-empty | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 testsuite/md5sum/md5sum-c-empty
diff --git a/testsuite/md5sum/md5sum-c-empty b/testsuite/md5sum/md5sum-c-empty
new file mode 100644
index 0000000..3a3ed72
--- /dev/null
+++ b/testsuite/md5sum/md5sum-c-empty
@@ -0,0 +1,5 @@
+# An empty file passed to -c must error out.
+
+touch empty
+busybox md5sum -c empty && exit 1
+exit 0
--
2.6.2
["0002-md5_sha1_sum-error-out-on-c-empty-file.patch" (0002-md5_sha1_sum-error-out-on-c-empty-file.patch)]
From 7bc302f6d05290803702037389cce39215b7f199 Mon Sep 17 00:00:00 2001
From: Lauri Kasanen <curaga@operamail.com>
Date: Sat, 25 Jun 2016 20:46:13 +0300
Subject: [PATCH 2/2] md5_sha1_sum: error out on -c empty file
This is needed to match GNU md5sum behavior.
Signed-off-by: Lauri Kasanen <curaga@operamail.com>
---
coreutils/md5_sha1_sum.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 1a5342e..89af9a3 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -200,6 +200,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
char *line;
int count_total = 0;
int count_failed = 0;
+ uint8_t found = 0;
pre_computed_stream = xfopen_stdin(*argv);
@@ -224,6 +225,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
}
*filename_ptr = '\0';
filename_ptr += 2;
+ found = 1;
hash_value = hash_file(filename_ptr);
@@ -244,6 +246,13 @@ 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 (!found) {
+ return_value = EXIT_FAILURE;
+
+ if (!(flags & FLAG_SILENT)) {
+ bb_error_msg("WARNING: no checksum lines found");
+ }
+ }
fclose_if_not_stdin(pre_computed_stream);
} else {
uint8_t *hash_value = hash_file(*argv);
--
2.6.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic