coreboot-kgpe-d16/util/cbfstool
Jacob Garber 2d58bf6a03 util/cbfstool: Prevent overflow of 16 bit multiplications
Considering the following integer multiplication:

    u64 = u16 * u16

What on earth, one might wonder, is the problem with this? Well, due to
C's unfortunately abstruse integer semantics, both u16's are implicitly
converted to int before the multiplication, which cannot hold
all possible values of a u16 * u16. Even worse, after overflow the
intermediate result will be a negative number, which during the
conversion to a u64 will be sign-extended to a huge integer. Not good.

The solution is to manually cast one of the u16 to a u32 or u64, which
are large enough to not have any overflow and will prevent the implicit
conversion. The type of the u64 is preferred, though a u32 is used
instead of size_t, since that can change depending on the platform.

Change-Id: I5391221d46d620d0e5bd629e2f9680be7a53342e
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Found-by: Coverity CID 12297{03,04,05,06,07,08,09,10}
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33986
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
2019-07-07 20:59:04 +00:00
..
console
flashmap util/cbfstool/flashmap: Correct local includes 2019-06-24 10:52:53 +00:00
lz4 util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
lzma util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
EXAMPLE
Makefile cbfstool: Add ifittool 2019-06-24 09:42:31 +00:00
Makefile.inc util/cbfstool: Add AMD BIOS compression tool for PSP 2019-07-03 21:28:43 +00:00
ProcessorBind.h
amdcompress.c util/cbfstool: Add AMD BIOS compression tool for PSP 2019-07-03 21:28:43 +00:00
cbfs-mkpayload.c util/cbfstool: fix build with clang 2018-07-20 16:06:29 +00:00
cbfs-mkstage.c util/cbfstool/cbfs-mkstage: Support x86_64 2018-12-19 06:06:49 +00:00
cbfs-payload-linux.c
cbfs.h Move compiler.h to commonlib 2018-10-08 16:57:27 +00:00
cbfs_image.c vboot: include vb2_sha.h when required 2019-05-09 06:32:44 +00:00
cbfs_image.h cbfstool: add unprocessed flag for file exporting 2018-11-16 09:47:35 +00:00
cbfs_sections.c Klocwork: Fix the Null pointer derefernce found by klocwork 2019-04-23 09:56:37 +00:00
cbfs_sections.h
cbfscomptool.c cbfstool: fix implicit declaration of strcasecmp 2018-07-27 10:48:17 +00:00
cbfstool.c cbfstool: show "preserved" flag in cbfstool layout output 2019-07-02 18:48:02 +00:00
coff.h
common.c util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
common.h util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
compress.c
default-x86.fmd Makefile.inc: Create a default SMMSTORE region 2019-02-06 18:15:59 +00:00
default.fmd
description.md util: Add description.md to each util 2018-07-26 13:26:50 +00:00
elf.h util/cbfstool: Support AMD64 rmodules 2018-12-19 06:05:52 +00:00
elfheaders.c util/cbfstool: Prevent overflow of 16 bit multiplications 2019-07-07 20:59:04 +00:00
elfparsing.h util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
fdt.h util/cbfstool: Support FIT payloads 2018-06-15 09:13:24 +00:00
fit.c cbfstool/fit: need inttypes.h for PRIx64 2019-06-26 09:19:00 +00:00
fit.h cbfstool: Drop update-fit option 2019-06-24 09:45:00 +00:00
flashmap_tests.c
fmap_from_fmd.c cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmap_from_fmd.h
fmaptool.c
fmd.c
fmd.h cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_parser.c_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_parser.h_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_parser.y cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_scanner.c_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_scanner.h_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_scanner.l cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fv.h
ifittool.c util/cbfstool/ifittool: use strtol function instead of atoi 2019-07-01 13:44:48 +00:00
ifwitool.c Move compiler.h to commonlib 2018-10-08 16:57:27 +00:00
linux.h util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
linux_trampoline.S linux_trampoline: use trampoline RAM for the GDT 2018-07-18 21:32:26 +00:00
linux_trampoline.c linux_trampoline: use trampoline RAM for the GDT 2018-07-18 21:32:26 +00:00
linux_trampoline.h
option.h
partitioned_file.c
partitioned_file.h
rmodtool.c
rmodule.c rmodule: Add support for R_X86_64_PLT32 2019-03-05 19:36:52 +00:00
rmodule.h util/cbfstool/rmodule.{c,h}: Fix typo and correct header 2018-11-22 14:58:38 +00:00
swab.h
xdr.c