From 5033b4f58f71e1535ab83d35dfcd8bb1b0384e22 Mon Sep 17 00:00:00 2001 From: Ulrich Ölmann Date: Fri, 8 Feb 2019 08:15:26 +0100 Subject: common: state: harmonize code with dt-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Insert a helpful size check that is an outcome of the following dt-utils commits: | commit a6eb5350be0f7a5673162d20f2dd72569d5a4d0c | Author: Markus Pargmann | Date: Fri May 27 13:53:40 2016 +0200 | | barebox-state: Import updated state code | | Signed-off-by: Markus Pargmann | commit 583acea6669550ffa7ffb465301ddb3529206afc | Author: Sascha Hauer | Date: Thu Mar 23 11:29:50 2017 +0100 | | state: backend-direct: Fix max_size | | The max_size in the direct backend includes the meta data, so | substract its size when determing the max data size we can store. | | Signed-off-by: Sascha Hauer | commit dcf781f1b3d15aff5f5ff0b604bff447dee2040c | Author: Sascha Hauer | Date: Thu Mar 23 12:59:48 2017 +0100 | | state: backend_bucket_direct: max_size is always given | | max_size is always != 0, so if(direct->max_size) can be skipped. | | Signed-off-by: Sascha Hauer Signed-off-by: Ulrich Ölmann Signed-off-by: Sascha Hauer --- common/state/backend_bucket_direct.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common/state/backend_bucket_direct.c') diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c index 9d6a337e66..1f00b0fb2f 100644 --- a/common/state/backend_bucket_direct.c +++ b/common/state/backend_bucket_direct.c @@ -110,6 +110,9 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket int ret; struct state_backend_storage_bucket_direct_meta meta; + if (len > direct->max_size - sizeof(meta)) + return -E2BIG; + ret = lseek(direct->fd, direct->offset, SEEK_SET); if (ret < 0) { dev_err(direct->dev, "Failed to seek file, %d\n", ret); -- cgit v1.2.3