[SeaBIOS] [PATCH] malloc: Add check to avoid dereference NULL pointer.

likejun (A) posted 1 patch 5 months, 4 weeks ago
Failed in applying to current master (apply log)
1 file changed, 6 insertions(+), 4 deletions(-)

[SeaBIOS] [PATCH] malloc: Add check to avoid dereference NULL pointer.

Posted by likejun (A) 5 months, 4 weeks ago
From: Kejun Li <likejun6@huawei.com<mailto:likejun6@huawei.com>>

Date: Mon, 22 Mar 2021 14:03:10 +0800

Subject: [PATCH] malloc: Add check to avoid dereference NULL pointer.



info = alloc_find_lowest() may return NULL, should check before

dereference it to avoid potential coredump.



Signed-off-by: Kejun Li <likejun6@huawei.com<mailto:likejun6@huawei.com>>

---

src/malloc.c | 10 ++++++----

1 file changed, 6 insertions(+), 4 deletions(-)



diff --git a/src/malloc.c b/src/malloc.c index 3733855..d355b77 100644

--- a/src/malloc.c

+++ b/src/malloc.c

@@ -544,10 +544,12 @@ malloc_prepboot(void)



     // Clear unused f-seg ram.

     struct allocinfo_s *info = alloc_find_lowest(&ZoneFSeg);

-    u32 size = info->range_end - info->range_start;

-    memset(memremap(info->range_start, size), 0, size);

-    dprintf(1, "Space available for UMB: %x-%x, %x-%x\n"

-            , RomEnd, base, info->range_start, info->range_end);

+    if (info) {

+        u32 size = info->range_end - info->range_start;

+        memset(memremap(info->range_start, size), 0, size);

+        dprintf(1, "Space available for UMB: %x-%x, %x-%x\n"

+                , RomEnd, base, info->range_start, info->range_end);

+    }



     // Give back unused high ram.

     info = alloc_find_lowest(&ZoneHigh);

--

2.19.1

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org