summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMartin Kurbanov <mmkurbanov@salutedevices.com>2024-06-16 16:34:18 +0300
committerHeiko Schocher <hs@denx.de>2024-07-03 08:05:19 +0200
commit27b169f9d0bed978bea1d86ab8d584da6ada54d0 (patch)
tree1a01a61defd74c3f566897dc54d6bd5c1afdeed1 /cmd
parentabae0b76f98647243d75770cdca5c1ad3302d5e8 (diff)
downloadu-boot-27b169f9d0bed978bea1d86ab8d584da6ada54d0.tar.gz
u-boot-27b169f9d0bed978bea1d86ab8d584da6ada54d0.tar.bz2
u-boot-27b169f9d0bed978bea1d86ab8d584da6ada54d0.zip
cmd: ubi: check 'updating' before calling ubi_more_update_data()
If 0 is passed to the 'bytes' parameter in the ubi_start_update(), there is no need to call the ubi_more_update_data(). Otherwise, there will be a double-free of 'vol->upd_buf'. Also check that the ubi_start_update() was called before calling the ubi_more_update_data(). Signed-off-by: Martin Kurbanov <mmkurbanov@salutedevices.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ubi.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmd/ubi.c b/cmd/ubi.c
index 287da345c1..92998af2b0 100644
--- a/cmd/ubi.c
+++ b/cmd/ubi.c
@@ -362,6 +362,11 @@ static int ubi_volume_continue_write(char *volume, void *buf, size_t size)
if (vol == NULL)
return ENODEV;
+ if (!vol->updating) {
+ printf("UBI volume update was not initiated\n");
+ return EINVAL;
+ }
+
err = ubi_more_update_data(ubi, vol, buf, size);
if (err < 0) {
printf("Couldnt or partially wrote data\n");
@@ -411,6 +416,10 @@ int ubi_volume_begin_write(char *volume, void *buf, size_t size,
return -err;
}
+ /* The volume is just wiped out */
+ if (!full_size)
+ return 0;
+
return ubi_volume_continue_write(volume, buf, size);
}