Skip to content

Commit 1c34b2a

Browse files
committed
Add null check for exception address
1 parent 1c1c3cb commit 1c34b2a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

plugin-dev/Source/Sentry/Private/Windows/WindowsCrashLogger.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ void FWindowsCrashLogger::PerformCrashLogging()
176176
}
177177
}
178178

179+
void* FWindowsCrashLogger::GetExceptionAddress(const sentry_ucontext_t* CrashContext)
180+
{
181+
if (CrashContext && CrashContext->exception_ptrs.ExceptionRecord)
182+
{
183+
return CrashContext->exception_ptrs.ExceptionRecord->ExceptionAddress;
184+
}
185+
186+
return nullptr;
187+
}
188+
179189
void FWindowsCrashLogger::WriteToErrorBuffers(const sentry_ucontext_t* CrashContext, HANDLE CrashedThreadHandle)
180190
{
181191
// Step 1: Write exception description to GErrorExceptionDescription
@@ -210,7 +220,7 @@ void FWindowsCrashLogger::WriteToErrorBuffers(const sentry_ucontext_t* CrashCont
210220
if (ContextWrapper)
211221
{
212222
// Perform stack walking using the crashed thread's context
213-
void* ProgramCounter = CrashContext->exception_ptrs.ExceptionRecord->ExceptionAddress;
223+
void* ProgramCounter = GetExceptionAddress(CrashContext);
214224

215225
#if !UE_VERSION_OLDER_THAN(5, 0, 0)
216226
FPlatformStackWalk::StackWalkAndDump(StackTrace, StackTraceSize, ProgramCounter, ContextWrapper);

plugin-dev/Source/Sentry/Private/Windows/WindowsCrashLogger.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class FWindowsCrashLogger
5858
*/
5959
void WriteToErrorBuffers(const sentry_ucontext_t* CrashContext, HANDLE CrashedThreadHandle);
6060

61+
/**
62+
* Safely retrieves the exception address from crash context.
63+
* Returns nullptr if the exception record is null or invalid.
64+
*/
65+
void* GetExceptionAddress(const sentry_ucontext_t* CrashContext);
66+
6167
private:
6268
// Thread handle
6369
HANDLE CrashLoggingThread;

0 commit comments

Comments
 (0)