You are not logged in.

#1 2023-03-23 08:25:06

patenteng
Member
Registered: 2022-10-12
Posts: 3

[SOLVED] sha256sum -c prints OK for a failed checksum

sha256sum -c prints OK for a failed checksum when the entry is not the first entry on the list. To reproduce run:

echo "123" > 1
echo "1234" > 2
echo "abc" > 3
sha256sum 1 2 3 > sums.sha256
echo "q" > 2
sha256sum -c sums.sha256
tail -n 2 sums.sha256 | sha256sum -c

The above script yields:

1: OK
2: OK
3: OK
sha256sum: WARNING: 1 computed checksum did NOT match
2: FAILED
3: OK
sha256sum: WARNING: 1 computed checksum did NOT match

I am using sha256sum (GNU coreutils) 9.2. Anyone else have the same problem? Is there a bug report?

Last edited by patenteng (2023-03-23 09:56:50)

Offline

#2 2023-03-23 09:07:44

Lithium Sulfate
Member
Registered: 2020-07-01
Posts: 20

Re: [SOLVED] sha256sum -c prints OK for a failed checksum

Cross-posting my response from your reddit post:

Likely a bug in coreutils 9.2. If you check the source:

    if (match)
      matched_checksums = true;
    else
      ++n_mismatched_checksums;
    
    if (!status_only)
    {
        /* ... */
    
        if ( ! matched_checksums)
          printf (": %s\n", _("FAILED"));
        else if (!quiet)
          printf (": %s\n", _("OK"));
    }

The printed output depends on matched_checksums which is set to true if the digest of a file matches, but never to false if it doesn't. It's only set to false once by default, at the beginning of the routine, before the file loop.

Seems the logic was changed in this commit for 9.2, and the bug doesn't occur in 9.1 (I just tested)

Offline

Board footer

Powered by FluxBB