From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] state: backend_raw: init digest earlier
Date: Mon, 24 Apr 2017 14:27:22 +0200 [thread overview]
Message-ID: <20170424122722.16275-1-s.hauer@pengutronix.de> (raw)
In backend_format_raw_pack() digest_length is used before it's
initialized in backend_raw_digest_init() which results in a too small
memory allocation for the raw backend. Fix this and prevent a memory
corruption.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/state/backend_format_raw.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/common/state/backend_format_raw.c b/common/state/backend_format_raw.c
index 232856a209..d76718cf82 100644
--- a/common/state/backend_format_raw.c
+++ b/common/state/backend_format_raw.c
@@ -211,6 +211,12 @@ static int backend_format_raw_pack(struct state_backend_format *format,
unsigned int size_data;
int ret;
+ if (backend_raw->algo) {
+ ret = backend_raw_digest_init(backend_raw);
+ if (ret)
+ return ret;
+ }
+
sv = list_last_entry(&state->variables, struct state_variable, list);
size_data = sv->start + sv->size;
size_full = size_data + sizeof(*header) + backend_raw->digest_length;
@@ -233,10 +239,6 @@ static int backend_format_raw_pack(struct state_backend_format *format,
sizeof(*header) - sizeof(uint32_t));
if (backend_raw->algo) {
- ret = backend_raw_digest_init(backend_raw);
- if (ret)
- return ret;
-
/* hmac over header and data */
ret = digest_update(backend_raw->digest, buf, sizeof(*header) + size_data);
if (ret) {
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2017-04-24 12:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20170424122722.16275-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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