]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cmd: ubi: check 'updating' before calling ubi_more_update_data()
authorMartin Kurbanov <mmkurbanov@salutedevices.com>
Sun, 16 Jun 2024 13:34:18 +0000 (16:34 +0300)
committerHeiko Schocher <hs@denx.de>
Wed, 3 Jul 2024 06:05:19 +0000 (08:05 +0200)
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>
cmd/ubi.c

index 287da345c104b0409531d3e5403a094bd4b30ba8..92998af2b02e4fb3d99f38228d82c826ee1e7a9a 100644 (file)
--- 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);
 }