bpo-36856: Handle possible overflow in faulthandler_stack_overflow (GH-13205)

(cherry picked from commit 6236c9823e)

Co-authored-by: Xi Ruoyao <xry111@mengyan1223.wang>
This commit is contained in:
Miss Islington (bot) 2019-05-27 17:14:21 -07:00 committed by GitHub
parent 0f352d44e7
commit 1062cf71fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 4 deletions

View File

@ -1120,13 +1120,26 @@ faulthandler_stack_overflow(PyObject *self)
{
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