From 63cfc10ce0af23ad5a79e7e6921419f0b6cfb5a6 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Fri, 28 Sep 2012 15:45:42 +0800 Subject: image: improve section table parsing Only add the endjunk region when we need to add data, and warn when we've got too much. Signed-off-by: Jeremy Kerr --- src/image.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/image.c b/src/image.c index d8dc5b1..6072f2d 100644 --- a/src/image.c +++ b/src/image.c @@ -330,6 +330,12 @@ static int image_find_regions(struct image *image) image->scnhdr[i].s_name, 8); bytes += regions[i + 3].size; + if (file_offset + regions[i+3].size > image->size) { + fprintf(stderr, "warning: file-aligned section %s " + "extends beyond end of file\n", + regions[i+3].name); + } + if (regions[i+2].data + regions[i+2].size != regions[i+3].data) { fprintf(stderr, "warning: gap in section table:\n"); @@ -356,7 +362,7 @@ static int image_find_regions(struct image *image) qsort(image->checksum_regions, image->n_checksum_regions, sizeof(struct region), cmp_regions); - if (bytes + image->cert_table_size != image->size) { + if (bytes + image->cert_table_size < image->size) { int n = image->n_checksum_regions++; struct region *r; @@ -372,6 +378,9 @@ static int image_find_regions(struct image *image) fprintf(stderr, "warning: data remaining[%zd vs %zd]: gaps " "between PE/COFF sections?\n", bytes + image->cert_table_size, image->size); + } else if (bytes + image->cert_table_size > image->size) { + fprintf(stderr, "warning: checksum areas are greater than " + "image size. Invalid section table?\n"); } /* record the size of non-signature data */ -- cgit 1.2.3-korg