summaryrefslogtreecommitdiff
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2021-03-04 21:49:30 -0800
committerGitHub <noreply@github.com>2021-03-04 21:49:30 -0800
commit02ac6f41e5569ec28d625bb005155903f64cc9ee (patch)
tree378d6d4792a64ea7cd5e106294449654cb73241d /Python/pylifecycle.c
parent2122e486307d5577cb5fb5e7cfd24095695bc7e9 (diff)
downloadcpython-git-02ac6f41e5569ec28d625bb005155903f64cc9ee.tar.gz
bpo-43390: Set SA_ONSTACK in PyOS_setsig (GH-24730)
This is friendlier to other in-process code that an extension module or embedding use could pull in such as CGo where tiny stacks are the norm and sigaltstack() has been used to provide for signal handlers. Without this, signals received by a process using tiny stacks may lead to stack overflow crashes.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index ec770841c8..d03c6c07f7 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -2884,7 +2884,10 @@ PyOS_setsig(int sig, PyOS_sighandler_t handler)
struct sigaction context, ocontext;
context.sa_handler = handler;
sigemptyset(&context.sa_mask);
- context.sa_flags = 0;
+ /* Using SA_ONSTACK is friendlier to other C/C++/Golang-VM code that
+ * extension module or embedding code may use where tiny thread stacks
+ * are used. https://bugs.python.org/issue43390 */
+ context.sa_flags = SA_ONSTACK;
if (sigaction(sig, &context, &ocontext) == -1)
return SIG_ERR;
return ocontext.sa_handler;