summaryrefslogtreecommitdiffstats
path: root/common/state
diff options
context:
space:
mode:
authorJan Remmet <j.remmet@phytec.de>2019-05-23 09:49:00 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-05-23 10:00:34 +0200
commit9271182f3b32d41a83ca802a63580c0c4fef9b9e (patch)
treee8039e7b660535233a812dd286dad486009df12e /common/state
parent5de7d31df289f0d7711648ea837680d33906c350 (diff)
downloadbarebox-9271182f3b32d41a83ca802a63580c0c4fef9b9e.tar.gz
barebox-9271182f3b32d41a83ca802a63580c0c4fef9b9e.tar.xz
common: state: check length
if written_length is read from a partial written bucket it may be to big and xmalloc will panic barebox. Check if the value is sane. Make read_len unsigned to avoid negative values. Signed-off-by: Jan Remmet <j.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/state')
-rw-r--r--common/state/backend_bucket_direct.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c
index 95ddb93106..0dbd334db8 100644
--- a/common/state/backend_bucket_direct.c
+++ b/common/state/backend_bucket_direct.c
@@ -52,7 +52,7 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
struct state_backend_storage_bucket_direct *direct =
get_bucket_direct(bucket);
struct state_backend_storage_bucket_direct_meta meta;
- ssize_t read_len;
+ uint32_t read_len;
void *buf;
int ret;
@@ -67,6 +67,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket
}
if (meta.magic == direct_magic) {
read_len = meta.written_length;
+ if (read_len > direct->max_size) {
+ dev_err(direct->dev, "Wrong length in meta data\n");
+ return -EINVAL;
+
+ }
} else {
if (meta.magic != ~0 && !!meta.magic)
bucket->wrong_magic = 1;