From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 28 May 2019 00:14:21 +0000 (-0700) Subject: bpo-36856: Handle possible overflow in faulthandler_stack_overflow (GH-13205) X-Git-Tag: v3.7.4rc1~96 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1062cf71faa14b90185cf159877083910df10f27;p=thirdparty%2FPython%2Fcpython.git bpo-36856: Handle possible overflow in faulthandler_stack_overflow (GH-13205) (cherry picked from commit 6236c9823ef3e8e2229b0598d3d8189adf5e00f2) Co-authored-by: Xi Ruoyao --- diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index ec5192832ce0..0dbd5a3342b0 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -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