From ba533a6df679dedbb90863380c04ba03053a90b5 Mon Sep 17 00:00:00 2001 From: Andrew Fasano Date: Wed, 27 Dec 2023 18:27:12 -0800 Subject: [PATCH] OSI: fix null ptr dereference when current thread is NULL --- panda/plugins/osi/os_intro.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/panda/plugins/osi/os_intro.c b/panda/plugins/osi/os_intro.c index a5b692ae1c3..b3b3f0bbaaf 100644 --- a/panda/plugins/osi/os_intro.c +++ b/panda/plugins/osi/os_intro.c @@ -180,9 +180,16 @@ OsiThread *get_current_thread(CPUState *cpu) { if((cachedInstructionCount != 0) && (cachedInstructionCount == cpu->rr_guest_instr_count)) { thread=(OsiThread *) g_malloc(sizeof(*thread)); + if (thread == NULL) { + return NULL; + } memcpy(thread, &cachedThread, sizeof(*thread)); } else { PPP_RUN_CB(on_get_current_thread, cpu, &thread); + if (thread == NULL) { + // Returns NULL if OSI can't find the current thread + return NULL; + } cachedInstructionCount = cpu->rr_guest_instr_count; memcpy(&cachedThread, thread, sizeof(cachedThread)); }