If a line specifies a binary checksum whose path contains two adjacent
spaces, when checking digests with -c the two spaces will be used as the
separator between the digest and the pathname instead of " *", as shown:

$ echo foo > "/tmp/two  spaces"
$ md5sum -b "/tmp/two  spaces"   # This is GNU md5sum
d3b07384d113edec49eaa6238ad5ff00 */tmp/two  spaces
$ md5sum -b "/tmp/two  spaces" | ./busybox md5sum -c
md5sum: can't open 'spaces': No such file or directory
spaces: FAILED
md5sum: WARNING: 1 of 1 computed checksums did NOT match

The patch looks for both markers and uses the one that is closer to the
start.
---
 coreutils/md5_sha1_sum.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 3b389cb6b..b7c1495d2 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -298,12 +298,17 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
                        while ((line = xmalloc_fgetline(pre_computed_stream)) 
!= NULL) {
                                uint8_t *hash_value;
                                char *filename_ptr;
+                               char *filename_ptr_bin;
 
                                count_total++;
                                filename_ptr = strstr(line, "  ");
                                /* handle format for binary checksums */
+                               filename_ptr_bin = strstr(line, " *");
                                if (filename_ptr == NULL) {
-                                       filename_ptr = strstr(line, " *");
+                                       filename_ptr = filename_ptr_bin;
+                               } else {
+                                       filename_ptr = (filename_ptr_bin != 
NULL && filename_ptr_bin < filename_ptr) ?
+                                               filename_ptr_bin : filename_ptr;
                                }
                                if (filename_ptr == NULL) {
                                        if (flags & FLAG_WARN) {
-- 
2.34.1

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to