From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Cc: bodhi <tlibertin@gmail.com>
Subject: [PATCH 1/2] scripts: kwboot: fix image check for padded images
Date: Sat, 11 Feb 2017 20:57:51 +0100 [thread overview]
Message-ID: <20170211195752.13616-1-u.kleine-koenig@pengutronix.de> (raw)
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
next reply other threads:[~2017-02-11 19:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-11 19:57 Uwe Kleine-König [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170211195752.13616-1-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=tlibertin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox