Joel Kitching has uploaded this change for review. ( https://review.coreboot.org/27540
Change subject: cbfstool/add-payload: initialize segment headers to 0 ......................................................................
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 --- M util/cbfstool/cbfs-mkpayload.c 1 file changed, 8 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/27540/1
diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c index e26c530..40ee06b 100644 --- a/util/cbfstool/cbfs-mkpayload.c +++ b/util/cbfstool/cbfs-mkpayload.c @@ -130,8 +130,9 @@
segments++; } - /* allocate the segment header array */ + /* Allocate and initialize the segment header array */ segs = calloc(segments, sizeof(*segs)); + memset(segs, 0, segments * sizeof(*segs)); if (segs == NULL) { ret = -1; goto out; @@ -253,6 +254,9 @@ struct cbfs_payload_segment segs[2]; int doffset, len = 0;
+ /* Initialize the segment header array */ + memset(&segs, 0, sizeof(segs)); + compress = compression_function(algo); if (!compress) return -1; @@ -307,6 +311,9 @@ uint32_t loadaddress = 0; uint32_t entrypoint = 0;
+ /* Initialize the segment header array */ + memset(&segs, 0, sizeof(segs)); + compress = compression_function(algo); if (!compress) return -1;