From: Frieder Schrempf <[email protected]>

find_active_slot() returns a strdup() copy of the slot name, which
distro_rauc_boot() never frees, so every boot attempt leaks it. The
strdup() result is not checked either and if it fails, get_slot() passes
NULL to strcmp().

Check the strdup() result and free the copy right after looking up
the slot. Use the name of the slot from then on.

Fixes: 7e5c2c782fb9 ("bootstd: Add implementation for bootmeth rauc")
Assisted-by: LLM
Signed-off-by: Frieder Schrempf <[email protected]>
---
 boot/bootmeth_rauc.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/boot/bootmeth_rauc.c b/boot/bootmeth_rauc.c
index 4a3f05103eb..3442b9e99d4 100644
--- a/boot/bootmeth_rauc.c
+++ b/boot/bootmeth_rauc.c
@@ -347,6 +347,10 @@ static int find_active_slot(char **slot_name, ulong 
*slot_tries)
                                return log_msg_ret("env", ret);
                        }
                        *slot_name = strdup(boot_order_list[i]);
+                       if (!*slot_name) {
+                               str_free_list(boot_order_list);
+                               return log_msg_ret("buf", -ENOMEM);
+                       }
                        *slot_tries = tries;
                        slot_found = true;
                }
@@ -415,16 +419,17 @@ static int distro_rauc_boot(struct udevice *dev, struct 
bootflow *bflow)
        if (ret)
                return log_msg_ret("env", ret);
 
-       /* Kernel command line arguments */
-       sprintf(raucargs, "rauc.slot=%s", active_slot);
-       ret = env_set("raucargs", raucargs);
-       if (ret)
-               return log_msg_ret("env", ret);
-
        /* Active slot info */
        slot = get_slot(priv, active_slot);
+       free(active_slot);
        if (!slot)
                return log_msg_ret("env", -ENOENT);
+
+       /* Kernel command line arguments */
+       sprintf(raucargs, "rauc.slot=%s", slot->name);
+       ret = env_set("raucargs", raucargs);
+       if (ret)
+               return log_msg_ret("env", ret);
        ret = env_set_hex("distro_bootpart", slot->boot_part);
        if (ret)
                return log_msg_ret("env", ret);
@@ -441,7 +446,7 @@ static int distro_rauc_boot(struct udevice *dev, struct 
bootflow *bflow)
                return log_msg_ret("load", ret);
 
        log_info("INFO: Booting slot %s, %lu of %d tries left\n",
-                active_slot, active_slot_tries, 
CONFIG_BOOTMETH_RAUC_DEFAULT_TRIES);
+                slot->name, active_slot_tries, 
CONFIG_BOOTMETH_RAUC_DEFAULT_TRIES);
 
        log_debug("devtype: %s\n", env_get("devtype"));
        log_debug("devnum: %s\n", env_get("devnum"));

-- 
2.56.0

Reply via email to