From bebe65f104fbe4a9c16a23ed4cf197301e361b87 Mon Sep 17 00:00:00 2001 From: "systems-assistant[bot]" <221163467+systems-assistant[bot]@users.noreply.github.com> Date: Tue, 21 Oct 2025 13:49:01 -0400 Subject: [PATCH] rocr: fix nullptr dereference (#262) * rocr: fix nullptr dereference Return early in the case that malloc fails to avoid dereferencing of a null pointer on eventDescrp. Signed-off-by: Sunday Clement * rocr: Fix potential nullptr dereference returns early if sym->section() fails to properly acquire the object. Signed-off-by: Sunday Clement --------- Signed-off-by: Sunday Clement Co-authored-by: Sunday Clement --- .../rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp | 2 ++ projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index 39424cbd84..63d1221d52 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -539,6 +539,8 @@ typedef struct EventDescriptor_ { EventHandle CreateOsEvent(bool auto_reset, bool init_state) { EventDescriptor* eventDescrp; eventDescrp = (EventDescriptor*)malloc(sizeof(EventDescriptor)); + + if(!eventDescrp) { return nullptr; } pthread_mutex_init(&eventDescrp->mutex, NULL); pthread_cond_init(&eventDescrp->event, NULL); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp index 5ea6928e19..26aef009ef 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/loader/executable.cpp @@ -1614,6 +1614,8 @@ uint64_t ExecutableImpl::SymbolAddress(hsa_agent_t agent, code::Symbol* sym) uint64_t ExecutableImpl::SymbolAddress(hsa_agent_t agent, elf::Symbol* sym) { elf::Section* sec = sym->section(); + if(!sec) { return NULL; } + Segment* seg = SectionSegment(agent, sec); uint64_t vaddr = sec->addr() + sym->value(); return nullptr == seg ? 0 : (uint64_t) (uintptr_t) seg->Address(vaddr);