summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-04-24 13:14:10 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-04-24 14:19:20 +0200
commitbfb82d544d6b8000bce57c45c52a4008289da856 (patch)
tree4c0d60aabca5954ca3576c888a5f7198c9598c8c
parentf703b2ce5d04368b65c3c5e2fd1e250cd1a8ed72 (diff)
downloaddt-utils-bfb82d544d6b8000bce57c45c52a4008289da856.tar.gz
barebox-state: backend_raw: init digest earlier
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>
-rw-r--r--src/barebox-state/backend_format_raw.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/barebox-state/backend_format_raw.c b/src/barebox-state/backend_format_raw.c
index 232856a..d76718c 100644
--- a/src/barebox-state/backend_format_raw.c
+++ b/src/barebox-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) {