Skip to content

Commit aa46e0f

Browse files
committed
[RTL/x64] Fix a bug in RtlpUnwindInternal
Check if the stack pointer is out of bounds, before trying to unwind a frame. This will not fix any crashes, but it prevents simple crashes from going into a recursive exception.
1 parent 7215e54 commit aa46e0f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

sdk/lib/rtl/amd64/unwind.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,18 @@ RtlVirtualUnwind(
649649
return NULL;
650650
}
651651

652+
static __inline
653+
BOOL
654+
RtlpIsStackPointerValid(
655+
_In_ ULONG64 StackPointer,
656+
_In_ ULONG64 LowLimit,
657+
_In_ ULONG64 HighLimit)
658+
{
659+
return (StackPointer >= LowLimit) &&
660+
(StackPointer < HighLimit) &&
661+
((StackPointer & 7) == 0);
662+
}
663+
652664
/*!
653665
\remark The implementation is based on the description in this blog: http://www.nynaeve.net/?p=106
654666
@@ -699,6 +711,11 @@ RtlpUnwindInternal(
699711
/* Start looping */
700712
while (TRUE)
701713
{
714+
if (!RtlpIsStackPointerValid(UnwindContext.Rsp, StackLow, StackHigh))
715+
{
716+
return FALSE;
717+
}
718+
702719
/* Lookup the FunctionEntry for the current RIP */
703720
FunctionEntry = RtlLookupFunctionEntry(UnwindContext.Rip, &ImageBase, NULL);
704721
if (FunctionEntry == NULL)

0 commit comments

Comments
 (0)