<p>Joel Kitching has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/27540">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cbfstool/add-payload: initialize segment headers to 0<br><br>Some types of payload segment headers do not use all fields.<br>If these unused fields are not initialized to 0, they can<br>cause problems in other software which consumes payloads.<br><br>For example, PAYLOAD_SEGMENT_ENTRY does not use the compression<br>field.  If it happens to be a non-existent compression type,<br>the 'cbfstool extract' command fails.<br><br>BUG=https://ticket.coreboot.org/issues/170<br>TEST=cbfstool tianocore.cbfs create -s 2097152 -m x86<br>     cbfstool tianocore.cbfs add-payload -f UEFIPAYLOAD.fd -n payload -c lzma -v<br>     xxd tianocore.cbfs | head  # visually inspect compression field for 0<br><br>Change-Id: I359ed117ab4154438bac7172aebf608f7a022552<br>Signed-off-by: kitching@google.com<br>---<br>M util/cbfstool/cbfs-mkpayload.c<br>1 file changed, 8 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/27540/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/util/cbfstool/cbfs-mkpayload.c b/util/cbfstool/cbfs-mkpayload.c</span><br><span>index e26c530..40ee06b 100644</span><br><span>--- a/util/cbfstool/cbfs-mkpayload.c</span><br><span>+++ b/util/cbfstool/cbfs-mkpayload.c</span><br><span>@@ -130,8 +130,9 @@</span><br><span> </span><br><span>               segments++;</span><br><span>  }</span><br><span style="color: hsl(0, 100%, 40%);">-       /* allocate the segment header array */</span><br><span style="color: hsl(120, 100%, 40%);">+       /* Allocate and initialize the segment header array */</span><br><span>       segs = calloc(segments, sizeof(*segs));</span><br><span style="color: hsl(120, 100%, 40%);">+       memset(segs, 0, segments * sizeof(*segs));</span><br><span>   if (segs == NULL) {</span><br><span>          ret = -1;</span><br><span>            goto out;</span><br><span>@@ -253,6 +254,9 @@</span><br><span>      struct cbfs_payload_segment segs[2];</span><br><span>         int doffset, len = 0;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+     /* Initialize the segment header array */</span><br><span style="color: hsl(120, 100%, 40%);">+     memset(&segs, 0, sizeof(segs));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>        compress = compression_function(algo);</span><br><span>       if (!compress)</span><br><span>               return -1;</span><br><span>@@ -307,6 +311,9 @@</span><br><span>     uint32_t loadaddress = 0;</span><br><span>    uint32_t entrypoint = 0;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  /* Initialize the segment header array */</span><br><span style="color: hsl(120, 100%, 40%);">+     memset(&segs, 0, sizeof(segs));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>        compress = compression_function(algo);</span><br><span>       if (!compress)</span><br><span>               return -1;</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/27540">change 27540</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/27540"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I359ed117ab4154438bac7172aebf608f7a022552 </div>
<div style="display:none"> Gerrit-Change-Number: 27540 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joel Kitching <kitching@google.com> </div>