mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] scripts: kwboot: fix image check for padded images
@ 2017-02-11 19:57 Uwe Kleine-König
  2017-02-11 19:57 ` [PATCH 2/2] scripts/kwboot: new parameter -n to skip a number of NAKs Uwe Kleine-König
  2017-02-14  7:47 ` [PATCH 1/2] scripts: kwboot: fix image check for padded images Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2017-02-11 19:57 UTC (permalink / raw)
  To: barebox; +Cc: bodhi

When there is some padding between header and payload the claim

	header_size + image_size == file_size

fails. Relax the check accordingly to:

	header_size <= image_offset &&
	image_offset + image_size == file_size

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 scripts/kwboot.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/scripts/kwboot.c b/scripts/kwboot.c
index 9e4181e539ac..3ab26cd936c5 100644
--- a/scripts/kwboot.c
+++ b/scripts/kwboot.c
@@ -603,7 +603,7 @@ static int
 kwboot_check_image(unsigned char *img, size_t size)
 {
 	size_t i;
-	size_t header_size, image_size;
+	size_t header_size, image_size, image_offset;
 	unsigned char csum = 0;
 
 	if (size < 0x20) {
@@ -640,12 +640,20 @@ kwboot_check_image(unsigned char *img, size_t size)
 
 	image_size = img[0x4] | (img[0x5] << 8) |
 		(img[0x6] << 16) | (img[0x7] << 24);
+	image_offset = img[0xc] | (img[0xd] << 8) |
+		(img[0xe] << 16) | (img[0xf] << 24);
 
 	header_size = (img[0x9] << 16) | img[0xa] | (img[0xb] << 8);
 
-	if (header_size + image_size != size) {
-		fprintf(stderr, "Size mismatch (%zu + %zu != %zu)\n",
-			header_size, image_size, size);
+	if (header_size > image_offset) {
+		fprintf(stderr, "Header (%zu) expands over image start (%zu)\n",
+			header_size, image_offset);
+		return 1;
+	}
+
+	if (image_offset + image_size != size) {
+		fprintf(stderr, "Image doesn't end at file end (%zu + %zu != %zu)\n",
+			image_offset, image_size, size);
 		return 1;
 	}
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-14  7:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-11 19:57 [PATCH 1/2] scripts: kwboot: fix image check for padded images Uwe Kleine-König
2017-02-11 19:57 ` [PATCH 2/2] scripts/kwboot: new parameter -n to skip a number of NAKs Uwe Kleine-König
2017-02-14  7:47 ` [PATCH 1/2] scripts: kwboot: fix image check for padded images Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox