]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bootstd: rauc: Fix potential memory leak
authorMartin Schwan <m.schwan@phytec.de>
Mon, 14 Jul 2025 13:30:08 +0000 (15:30 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 22 Jul 2025 19:53:17 +0000 (13:53 -0600)
Fix a potential memory leak, by checking the return value of realloc
first, before assigning it to the private list of slots.

Signed-off-by: Martin Schwan <m.schwan@phytec.de>
boot/bootmeth_rauc.c

index fc60e6e355dabef4d58bf1203997b41d99c536f9..6abbd25704bdf218bb0b3a02306993584088d2c7 100644 (file)
@@ -168,13 +168,17 @@ static int distro_rauc_read_bootflow(struct udevice *dev, struct bootflow *bflow
             (slot = strsep(&boot_order_copy, " "));
             i++) {
                struct distro_rauc_slot *s;
+               struct distro_rauc_slot **new_slots;
 
                s = calloc(1, sizeof(struct distro_rauc_slot));
                s->name = strdup(slot);
                s->boot_part = simple_strtoul(strsep(&parts, ","), NULL, 10);
                s->root_part = simple_strtoul(strsep(&parts, ","), NULL, 10);
-               priv->slots = realloc(priv->slots, (i + 1) *
-                                     sizeof(struct distro_rauc_slot));
+               new_slots = realloc(priv->slots, (i + 1) *
+                                   sizeof(struct distro_rauc_slot));
+               if (!new_slots)
+                       return log_msg_ret("buf", -ENOMEM);
+               priv->slots = new_slots;
                priv->slots[i - 1] = s;
                priv->slots[i]->name = NULL;
        }