]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_memory: avoid possible null pointer dereference
authorSughosh Ganu <sughosh.ganu@linaro.org>
Tue, 30 Jul 2024 11:11:30 +0000 (16:41 +0530)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 31 Jul 2024 07:54:42 +0000 (09:54 +0200)
Populate the previous memory descriptor node pointer only after it's
parent struct has been initialised. The compiler fixes this logic to
do the right thing, but it is better to have correct code in place.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
lib/efi_loader/efi_memory.c

index 9a62864a0026edbe741cd39a798d17493577a341..6c5cc26ae380a5e7a2eb4a8daee2141c24ec99fa 100644 (file)
@@ -138,7 +138,7 @@ static void efi_mem_sort(void)
                merge_again = false;
                list_for_each(lhandle, &efi_mem) {
                        struct efi_mem_list *lmem;
-                       struct efi_mem_desc *prev = &prevmem->desc;
+                       struct efi_mem_desc *prev;
                        struct efi_mem_desc *cur;
                        uint64_t pages;
 
@@ -149,6 +149,7 @@ static void efi_mem_sort(void)
                        }
 
                        cur = &lmem->desc;
+                       prev = &prevmem->desc;
 
                        if ((desc_get_end(cur) == prev->physical_start) &&
                            (prev->type == cur->type) &&