mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-21 03:12:48 +02:00
cksum: use more defensive escaping for --check
cksum --check is often the first interaction
users have with possibly untrusted downloads, so we should try
to be as defensive as possible when processing it.
Specifically we currently only escape \n characters in file names
presented in checksum files being parsed with cksum --check.
This gives some possibilty of dumping arbitrary data to the terminal
when checking downloads from an untrusted source.
This change gives these advantages:
1. Avoids dumping arbitrary data to vulnerable terminals
2. Avoids visual deception with ansi codes hiding checksum failures
3. More secure if users copy and paste file names from --check output
4. Simplifies programmatic parsing
Note this changes programmatic parsing, but given the original
format was so awkward to parse, I expect that's extremely rare.
I was not able to find example in the wild at least.
To parse the new format from from shell, you can do something like:
cksum -c checksums | while IFS= read -r line; do
case $line in
*': FAILED')
filename=$(eval "printf '%s' ${line%: FAILED}")
cp -v "$filename" /quarantine
;;
esac
done
This change also slightly reduces the size of the sum(1) utility.
This change also apples to md5sum, sha*sum, and b2sum.
* src/cksum.c (digest_check): Call quotef() instead of
cksum(1) specific quoting.
* tests/cksum/md5sum-bsd.sh: Adjust accordingly.
* doc/coreutils.texi (cksum general options): Describe the
shell quoting used for problematic file names.
* NEWS: Mention the change in behavior.
Reported by: Aaron Rainbolt
This commit is contained in:
@@ -4130,7 +4130,11 @@ By default, for each valid line, one line is written to standard
|
||||
output indicating whether the named file passed the test.
|
||||
After all checks have been performed, if there were any failures,
|
||||
a warning is issued to standard error.
|
||||
Use the @option{--status} option to inhibit that output.
|
||||
If file names contain problematic characters,
|
||||
they will be quoted in a way suitable for POSIX-compatible shells,
|
||||
so that any file name is represented unambiguously and safely.
|
||||
|
||||
Use the @option{--status} option to inhibit the output described above.
|
||||
If any listed file cannot be opened or read, if any valid line has
|
||||
a checksum inconsistent with the associated file, or if no valid
|
||||
line is found, @command{cksum} exits with nonzero status. Otherwise,
|
||||
|
||||
Reference in New Issue
Block a user