image: improve handling of unaligned section tables
Rather than overrunning the heap, explicitly allocate the pad area for cases where we've aligned-up the section table sizes. Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
parent
142ba5c1b3
commit
de78e0cde9
1 changed files with 22 additions and 0 deletions
22
src/image.c
22
src/image.c
|
@ -405,6 +405,7 @@ struct image *image_load(const char *filename)
|
|||
if (rc)
|
||||
goto err;
|
||||
|
||||
reparse:
|
||||
rc = image_pecoff_parse(image);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
@ -413,6 +414,27 @@ struct image *image_load(const char *filename)
|
|||
if (rc)
|
||||
goto err;
|
||||
|
||||
/* Some images may have incorrectly aligned sections, which get rounded
|
||||
* up to a size that is larger that the image itself (and the buffer
|
||||
* that we've allocated). We would have generated a warning about this,
|
||||
* but we can improve our chances that the verification hash will
|
||||
* succeed by padding the image out to the aligned size, and including
|
||||
* the pad in the signed data.
|
||||
*
|
||||
* In this case, do a realloc, but that may peturb the addresses that
|
||||
* we've calculated during the pecoff parsing, so we need to redo that
|
||||
* too.
|
||||
*/
|
||||
if (image->data_size > image->size) {
|
||||
image->buf = talloc_realloc(image, image->buf, uint8_t,
|
||||
image->data_size);
|
||||
memset(image->buf + image->size, 0,
|
||||
image->data_size - image->size);
|
||||
image->size = image->data_size;
|
||||
|
||||
goto reparse;
|
||||
}
|
||||
|
||||
return image;
|
||||
err:
|
||||
talloc_free(image);
|
||||
|
|
Loading…
Reference in a new issue