XXXsum: handle binary sums with " " in the path

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

function                                             old     new   delta
md5_sha1_sum_main                                    503     496      -7

Signed-off-by: Emanuele Giacomelli <emanuele.giacomelli@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Emanuele Giacomelli 2022-01-07 14:17:48 +01:00 committed by Denys Vlasenko
parent e7ff29402d
commit 84a1305888

View File

@ -300,12 +300,10 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
char *filename_ptr; char *filename_ptr;
count_total++; count_total++;
filename_ptr = strstr(line, " "); filename_ptr = strchr(line, ' ');
/* handle format for binary checksums */ if (filename_ptr == NULL
if (filename_ptr == NULL) { || (filename_ptr[1] != ' ' && filename_ptr[1] != '*')
filename_ptr = strstr(line, " *"); ) {
}
if (filename_ptr == NULL) {
if (flags & FLAG_WARN) { if (flags & FLAG_WARN) {
bb_simple_error_msg("invalid format"); bb_simple_error_msg("invalid format");
} }