coreboot/util
Julius Werner ee87885343 cbfs-compression-tool: Fix minor edge cases in algorithm type parsing
This patch adds two minor improvements to the way cbfs-compression-tool
parses the compression algorithm type that is passed through the -t
option of the 'compress' subcommand. These improvements are intended
to prevent accidents and unexpected behavior when using the
cbfs-compression-tool, in particular in automated contexts such as a
Makefile rule.

In the first part of this patch, a return statement is inserted after
the 'if (algo->name == NULL)' check of the compress() function. This
causes the function to exit immediately and subsequently abort the
program when the algorithm type was not detected correctly. Previously,
execution would continue with the 'algo' pointer pointing to the zeroed
out stopper entry of the types_cbfs_compression[] array. The ultimate
effect of this would be to pass 0 as 'algo->type' to the
compression_function() function, which happens to be the same
enumeration value as is used for CBFS_COMPRESS_NONE, leading to a valid
compression function result that matches the behavior of no compression.
Thus, if a script calling cbfs-compression-tool compress contained a
typo in the -t parameter, it would continue running with an unintended
compression result rather than immediately exiting cleanly.

In the second part of this patch, the strcmp() function is replaced with
strcasecmp() when comparing 'algo->name' with the 'algoname' parameter
that was passed to the compress() function. strcasecmp() uses an
identical function signature as strcmp() and is thus suitable as a
drop-in replacement, but it differs in behavior: rather than only
returning a result of 0 when the two NULL-terminated input strings are
character by character identical, the strcasecmp() function applies a
weaker concept of identity where characters of the latin alphabet
(hexadecimal ranges 0x41 through 0x5a and 0x61 through 0x7a) are also
considered identical to other characters that differ from them only in
their case. This causes the -t parameter of cbfs-compression-tool
compress to also accept lowercase spellings of the available compression
algorithms, such as "lz4" instead of "LZ4" and "lzma" instead of "LZMA".
As an unintended but harmless side-effect, mixed-case spellings such as
"lZ4" or "LZmA" will also be recognized as valid compression algorithms.
(Note that since the character "4" (hexadecimal 0x34) of the "LZ4"
compression type name is not part of the above-mentioned ranges of latin
alphabet characters, no new substitutions become valid for that part of
the "LZ4" string with this patch.)

Change-Id: I375dbaeefaa0d4b0c5be81bf7668f8f330f1cf61
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/26389
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
2018-05-21 13:25:49 +00:00
..
abuild util/abuild: Disable unspecified payload options 2018-05-17 12:06:33 +00:00
acpi
amdfwtool
amdtools
archive
arm_boot_tools/mksunxiboot
autoport
bimgtool
bincfg
board_status
broadcom
cbfstool cbfs-compression-tool: Fix minor edge cases in algorithm type parsing 2018-05-21 13:25:49 +00:00
cbmem util/cbmem: Fix compare function for qsort 2018-05-18 20:13:47 +00:00
checklist
chromeos
crossgcc
docker util/docker: Update coreboot-sdk dockerfile dependencies list 2018-05-21 13:21:39 +00:00
dtd_parser
ectool
exynos
futility
fuzz-tests
genbuild_h
genprof
gitconfig
ifdfake
ifdtool
intelmetool
inteltool
intelvbttool
ipqheader
k8resdump
kbc1126
kconfig
lint
marvell
me_cleaner
mma
msrtool msrtool: add VIA C7 2018-05-15 11:14:10 +00:00
mtkheader
nvidia
nvramtool
optionlist
post
qualcomm/scripts/cmm
release
riscv
rockchip
romcc
sconfig devicetree: Add USB device type 2018-05-11 08:59:51 +00:00
scripts
showdevicetree
spkmodem_recv
superiotool
testing util/testing: Update junit.xml to support coreboot builds 2018-05-21 13:17:38 +00:00
uio_usbdebug
vgabios
viatool
x86
xcompile