]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: fix reporting of failed checks
authorPádraig Brady <P@draigBrady.com>
Thu, 23 Mar 2023 12:31:24 +0000 (12:31 +0000)
committerPádraig Brady <P@draigBrady.com>
Thu, 23 Mar 2023 12:36:53 +0000 (12:36 +0000)
This applies to all checksumming utilities,
where we incorrectly report all subsequent files as checking 'OK'
once any file has passed a digest check.
The exit status was not impacted, only the printed status.

* src/digest.c (digest_check): Use the correct state variable
to determine if the _current_ file has passed or not.
* tests/misc/md5sum.pl: Add a test case.
Fixes https://bugs.gnu.org/62403

src/digest.c
tests/misc/md5sum.pl

index 6ee8a485474ba9fe19e72b42905e6844cb0b26fd..ab32968db7326ca281addd852ca4cb931df0ab99 100644 (file)
@@ -1254,14 +1254,14 @@ digest_check (char const *checkfile_name)
 
               if (!status_only)
                 {
-                  if ( ! matched_checksums || ! quiet)
+                  if (! match || ! quiet)
                     {
                       if (needs_escape)
                         putchar ('\\');
                       print_filename (filename, needs_escape);
                     }
 
-                  if ( ! matched_checksums)
+                  if (! match)
                     printf (": %s\n", _("FAILED"));
                   else if (!quiet)
                     printf (": %s\n", _("OK"));
index 186aca9775915b0d3e1449363a0d87b8cdd46851..d712664b2ba9f31aa33fd2f0cfc20993805d511b 100755 (executable)
@@ -101,6 +101,16 @@ my @Tests =
                   . "md5sum: WARNING: 1 line is improperly formatted\n"
                   . "md5sum: WARNING: 2 computed checksums did NOT match\n"},
                                 {EXIT=> 1}],
+     # Ensure we use appropriate state to track failures (broken in 9.2)
+     ['check-multifail-state', '--check', '--warn',
+                                {IN=>{'f.md5' =>
+                                      "$degenerate  f\n"
+                                      . "$degenerate  g\n"
+                                      . "$degenerate  f\n" }},
+                                {AUX=> {f=> ''}}, {AUX=> {g=> 'a'}},
+                                {OUT=>"f: OK\ng: FAILED\nf: OK\n"},
+              {ERR=>"md5sum: WARNING: 1 computed checksum did NOT match\n"},
+                                {EXIT=> 1}],
      # The sha1sum and md5sum drivers share a lot of code.
      # Ensure that md5sum does *not* share the part that makes
      # sha1sum accept BSD format.