[coreboot-gerrit] Change in coreboot[master]: cbfstool/add-payload: initialize segment headers to 0

Joel Kitching (Code Review) gerrit at coreboot.org
Thu Jul 19 01:49:24 CEST 2018


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 at 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;

-- 
To view, visit https://review.coreboot.org/27540
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I359ed117ab4154438bac7172aebf608f7a022552
Gerrit-Change-Number: 27540
Gerrit-PatchSet: 1
Gerrit-Owner: Joel Kitching <kitching at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180718/f22d6db5/attachment.html>


More information about the coreboot-gerrit mailing list