From a302e7f46b582a163758bc9d53f8801e7cdb2443 Mon Sep 17 00:00:00 2001 From: Joel Kitching Date: Thu, 19 Jul 2018 07:36:38 +0800 Subject: [PATCH] cbfstool/add-payload: initialize segment headers to 0 Some types of payload segment headers do not use all fields. If these unused fields are not initialized to 0, they can cause problems in other software which consumes payloads. For example, PAYLOAD_SEGMENT_ENTRY does not use the compression field. If it happens to be a non-existent compression type, the 'cbfstool extract' command fails. BUG=https://ticket.coreboot.org/issues/170 TEST=cbfstool tianocore.cbfs create -s 2097152 -m x86 cbfstool tianocore.cbfs add-payload -f UEFIPAYLOAD.fd -n payload -c lzma -v xxd tianocore.cbfs | head # visually inspect compression field for 0 Change-Id: I359ed117ab4154438bac7172aebf608f7a022552 Signed-off-by: kitching@google.com Reviewed-on: https://review.coreboot.org/27540 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner Reviewed-by: Patrick Georgi --- util/cbfstool/cbfs-mkpayload.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c index e26c530106..8464a2bbb9 100644 --- a/util/cbfstool/cbfs-mkpayload.c +++ b/util/cbfstool/cbfs-mkpayload.c @@ -130,7 +130,7 @@ int parse_elf_to_payload(const struct buffer *input, struct buffer *output, segments++; } - /* allocate the segment header array */ + /* Allocate and initialize the segment header array */ segs = calloc(segments, sizeof(*segs)); if (segs == NULL) { ret = -1; @@ -250,7 +250,7 @@ int parse_flat_binary_to_payload(const struct buffer *input, enum comp_algo algo) { comp_func_ptr compress; - struct cbfs_payload_segment segs[2]; + struct cbfs_payload_segment segs[2] = {0}; int doffset, len = 0; compress = compression_function(algo); @@ -295,7 +295,7 @@ int parse_fv_to_payload(const struct buffer *input, struct buffer *output, enum comp_algo algo) { comp_func_ptr compress; - struct cbfs_payload_segment segs[2]; + struct cbfs_payload_segment segs[2] = {0}; int doffset, len = 0; firmware_volume_header_t *fv; ffs_file_header_t *fh;