Skip to content

Commit

Permalink
bpo-36856: Handle possible overflow in faulthandler_stack_overflow (G…
Browse files Browse the repository at this point in the history
  • Loading branch information
xry111 authored and vstinner committed May 11, 2019
1 parent 79972f1 commit 6236c98
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Modules/faulthandler.c
Expand Up @@ -1121,13 +1121,26 @@ faulthandler_stack_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
{
size_t depth, size;
uintptr_t sp = (uintptr_t)&depth;
uintptr_t stop;
uintptr_t stop, lower_limit, upper_limit;

faulthandler_suppress_crash_report();
depth = 0;
stop = stack_overflow(sp - STACK_OVERFLOW_MAX_SIZE,
sp + STACK_OVERFLOW_MAX_SIZE,
&depth);

if (STACK_OVERFLOW_MAX_SIZE <= sp) {
lower_limit = sp - STACK_OVERFLOW_MAX_SIZE;
}
else {
lower_limit = 0;
}

if (UINTPTR_MAX - STACK_OVERFLOW_MAX_SIZE >= sp) {
upper_limit = sp + STACK_OVERFLOW_MAX_SIZE;
}
else {
upper_limit = UINTPTR_MAX;
}

stop = stack_overflow(lower_limit, upper_limit, &depth);
if (sp < stop)
size = stop - sp;
else
Expand Down

0 comments on commit 6236c98

Please sign in to comment.