com php-src: do not try to handle signals, when globals are inconsistent: Zend/zend_signal.c

[email protected] (Anatol Belski)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    c7b2c698d03466959874d933b1a44be125e25e4f
Author:    Anatol Belski <[email protected]>         Thu, 2 Mar 2017 16:39:32 +0100
Parents:   fab5ce347c57827b86c658afdb33825cf095cb5e
Branches:  PHP-7.0 PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=c7b2c698d03466959874d933b1a44be125e25e4f

Log:
do not try to handle signals, when globals are inconsistent

Changed paths:
  M  Zend/zend_signal.c


Diff:
diff --git a/Zend/zend_signal.c b/Zend/zend_signal.c
index b4f5741..ba550a1 100644
--- a/Zend/zend_signal.c
+++ b/Zend/zend_signal.c
@@ -74,12 +74,17 @@ void zend_signal_handler_defer(int signo, siginfo_t *siginfo, void *context)
 {
 	int errno_save = errno;
 	zend_signal_queue_t *queue, *qtmp;
+	zend_bool is_handling_safe = 1;
 
 #ifdef ZTS
 	ZEND_TSRMLS_CACHE_UPDATE();
+	/* A signal could hit after TSRM shutdown, in this case globals are already freed. */
+	if (NULL == TSRMG_BULK_STATIC(zend_signal_globals_id, zend_signal_globals_t *)) {
+		is_handling_safe = 0;
+	}
 #endif
 
-	if (EXPECTED(SIGG(active))) {
+	if (EXPECTED(is_handling_safe && SIGG(active))) {
 		if (UNEXPECTED(SIGG(depth) == 0)) { /* try to handle signal */
 			if (UNEXPECTED(SIGG(blocked))) {
 				SIGG(blocked) = 0;
@@ -162,7 +167,14 @@ static void zend_signal_handler(int signo, siginfo_t *siginfo, void *context)
 	int errno_save = errno;
 	struct sigaction sa = {{0}};
 	sigset_t sigset;
-	zend_signal_entry_t p_sig = SIGG(handlers)[signo-1];
+	zend_signal_entry_t p_sig;
+#ifdef ZTS
+	if (NULL == TSRMG_BULK_STATIC(zend_signal_globals_id, zend_signal_globals_t *)) {
+		p_sig.flags = 0;
+		p_sig.handler = SIG_DFL;
+	} else 
+#endif
+	p_sig = SIGG(handlers)[signo-1];
 
 	if (p_sig.handler == SIG_DFL) { /* raise default handler */
 		if (sigaction(signo, NULL, &sa) == 0) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.