Subject: bug#64392: cksum: escaping issues of --check output

From: Christoph Anton Mitterer <[email-masked]>
Date: Sat, 01 Jul 2023 02:10:49 +0200

Hey.

It seems to me that the output of --check mode in cksum (and likely
also in md5sum and friends) suffers from improper escaping (which,
IIRC, is not even documented for that output... but may be wrong):

$ touch a $'new\nline' '\n' z
$ ls -al
total 0
drwxr-xr-x 1 calestyo calestyo  24 Jul  1 02:01  .
drwxr-xr-x 1 calestyo calestyo 176 Jul  1 01:48  ..
-rw-r--r-- 1 calestyo calestyo   0 Jul  1 02:01  a
-rw-r--r-- 1 calestyo calestyo   0 Jul  1 02:01 'new'$'\n''line'
-rw-r--r-- 1 calestyo calestyo   0 Jul  1 02:01  z
-rw-r--r-- 1 calestyo calestyo   0 Jul  1 02:01 '\n'

$ cksum -a sha512 --tag * > sums.tagged
$ cksum -a sha512 --untagged * > sums.untagged

$ cat sums.tagged 
SHA512 (a) = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
\SHA512 (\\n) = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
\SHA512 (new\nline) = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
SHA512 (z) = cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
$ cat sums.untagged 
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e  a
\cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e  \\n
\cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e  new\nline
65bb946645079f3ebfa931460430c1676d656e455e5a6266b85fa0c78f08f63507eb417b70f67106c8ad9cdebeacb29fa770e86b1624763f310f1ebb6bd0542a  sums.tagged
cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e  z

$ cksum -c sums.tagged
a: OK
\n: OK
\new\nline: OK
z: OK
$ cksum -c sums.untagged 
cksum: sums.untagged: no properly formatted checksum lines found

$ sha512sum -c sums.untagged 
a: OK
\n: OK
\new\nline: OK
sums.tagged: OK
z: OK

Assuming the same rules for the --check output as for the sums files, a
leading \ should serve as the escaping indicator.

So for:
   \new\nline: OK
that would be fine but for:
   \n: OK
it's not but would rather need to be:
   \\\n: OK

The failed cases may be similarly affected by this.

Thanks,
Chris.

btw: Though it's probably too late to change, I think the output format
is rather unfortunate.
It should have been more closely to the BSD style format used for the
sums file, e.g. something like:
   <algo> (<filename>) = <OK|failed|not found|etc.>
again with the optional leading \ to indicate escaping.

The problem with the current format is especially, that it's not
possible to determine the alog, which may however be of interest if
there are more than one per file.