From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
barebox@lists.infradead.org
Subject: [PATCH 2/2] scripts: kwbimage: fix mis-sized payload
Date: Tue, 12 Nov 2013 21:58:04 +0100 [thread overview]
Message-ID: <1384289884-8832-2-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1384289884-8832-1-git-send-email-sebastian.hesselbarth@gmail.com>
Image payload size should always be a multiple of 4 bytes. This fixes
mis-sized image payload by allocating payload buffer as multiple of 4
but load true filesize into the payload buffer.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
scripts/kwbimage.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index 4ebb07f..82cf21c 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -685,6 +685,7 @@ static int image_create_payload(void *payload_start, size_t payloadsz,
const char *payload_filename)
{
FILE *payload;
+ struct stat s;
uint32_t *payload_checksum =
(uint32_t *) (payload_start + payloadsz);
int ret;
@@ -696,7 +697,14 @@ static int image_create_payload(void *payload_start, size_t payloadsz,
return -1;
}
- ret = fread(payload_start, payloadsz, 1, payload);
+ ret = stat(payload_filename, &s);
+ if (ret < 0) {
+ fprintf(stderr, "Cannot stat payload file %s\n",
+ payload_filename);
+ return ret;
+ }
+
+ ret = fread(payload_start, s.st_size, 1, payload);
if (ret != 1) {
fprintf(stderr, "Cannot read payload file %s\n",
payload_filename);
@@ -747,7 +755,8 @@ static void *image_create_v0(struct image_cfg_element *image_cfg,
return NULL;
}
- payloadsz = s.st_size;
+ /* payload size must be multiple of 32b */
+ payloadsz = 4 * ((s.st_size + 3)/4);
}
/* Headers, payload and 32-bits checksum */
@@ -875,7 +884,8 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
return NULL;
}
- payloadsz = s.st_size;
+ /* payload size must be multiple of 32b */
+ payloadsz = 4 * ((s.st_size + 3)/4);
}
/* The payload should be aligned on some reasonable
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-11-12 20:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-12 20:58 [PATCH 1/2] scripts: kwboot: fix missing soh initialization Sebastian Hesselbarth
2013-11-12 20:58 ` Sebastian Hesselbarth [this message]
2013-11-18 9:53 ` 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=1384289884-8832-2-git-send-email-sebastian.hesselbarth@gmail.com \
--to=sebastian.hesselbarth@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=thomas.petazzoni@free-electrons.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