From d0a58695d00640eafca49c934204e2c1c675fcba Mon Sep 17 00:00:00 2001 From: redfoxli Date: Tue, 9 Dec 2014 19:42:55 +0800 Subject: [PATCH 1/4] fix-bug-68571-to-php5.5 --- sapi/fpm/fpm/fastcgi.c | 1 + sapi/fpm/fpm/fpm_main.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sapi/fpm/fpm/fastcgi.c b/sapi/fpm/fpm/fastcgi.c index d2764a59b72..bcaef1b03ea 100644 --- a/sapi/fpm/fpm/fastcgi.c +++ b/sapi/fpm/fpm/fastcgi.c @@ -977,6 +977,7 @@ int fcgi_flush(fcgi_request *req, int close) if (safe_write(req, req->out_buf, len) != len) { req->keep = 0; + req->out_pos = req->out_buf; return 0; } diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 331342c2a2c..adc3f5b65af 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -672,8 +672,11 @@ void sapi_cgi_log_fastcgi(int level, char *message, size_t len) char *buf = malloc(len + 2); memcpy(buf, message, len); memcpy(buf + len, "\n", sizeof("\n")); - fcgi_write(request, FCGI_STDERR, buf, len+1); + ssize_t ret = fcgi_write(request, FCGI_STDERR, buf, len+1); free(buf); + if (ret <= 0) { + php_handle_aborted_connection(); + } } } /* }}} */ From 7953d830abbd178812c79e85a7a4dde96f164d75 Mon Sep 17 00:00:00 2001 From: redfoxli Date: Wed, 10 Dec 2014 21:58:57 +0800 Subject: [PATCH 2/4] follow C89 format --- sapi/fpm/fpm/fpm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index adc3f5b65af..ba6382ca73d 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -670,9 +670,10 @@ void sapi_cgi_log_fastcgi(int level, char *message, size_t len) */ if (CGIG(fcgi_logging) && request && message && len > 0) { char *buf = malloc(len + 2); + ssize_t ret = 0; memcpy(buf, message, len); memcpy(buf + len, "\n", sizeof("\n")); - ssize_t ret = fcgi_write(request, FCGI_STDERR, buf, len+1); + ret = fcgi_write(request, FCGI_STDERR, buf, len+1); free(buf); if (ret <= 0) { php_handle_aborted_connection(); From 8c2d91761aaa3b7b25c70df4d2320f85e9322e79 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 27 Jan 2015 22:11:23 +0800 Subject: [PATCH 3/4] Also Fixed #68571 in CGI SAPI, and some cleanup --- NEWS | 5 +++++ sapi/cgi/cgi_main.c | 7 +++++-- sapi/cgi/fastcgi.c | 1 + sapi/fpm/fpm/fastcgi.c | 2 +- sapi/fpm/fpm/fpm_main.c | 10 +++++----- sapi/tests/test006.phpt | 1 - 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index a9ddf575d5f..145660f8158 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2015, PHP 5.5.22 + - Date: . Fixed bug #45081 (strtotime incorrectly interprets SGT time zone). (Derick) . Fixed bug #55407 (Impossible to prototype DateTime::createFromFormat). @@ -13,6 +14,10 @@ PHP NEWS - Fileinfo: . Fixed bug #68827 (Double free with disabled ZMM). (Joshua Rogers) +- FPM: + . Fixed bug #68571 (core dump when webserver close the socket). + (redfoxli069 at gmail dot com, Laruence) + - OpenSSL: . Fixed bug #55618 (use case-insensitive cert name matching). (Daniel Lowrey) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index de9a4769992..1f84ab25976 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -730,13 +730,16 @@ static void sapi_cgi_log_message(char *message TSRMLS_DC) request = (fcgi_request*) SG(server_context); if (request) { - int len = strlen(message); + int ret, len = strlen(message); char *buf = malloc(len+2); memcpy(buf, message, len); memcpy(buf + len, "\n", sizeof("\n")); - fcgi_write(request, FCGI_STDERR, buf, len+1); + ret = fcgi_write(request, FCGI_STDERR, buf, len + 1); free(buf); + if (ret < 0) { + php_handle_aborted_connection(); + } } else { fprintf(stderr, "%s\n", message); } diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index 6a7e3a2e542..5e9e4c89c4c 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -1321,6 +1321,7 @@ int fcgi_flush(fcgi_request *req, int close) if (safe_write(req, req->out_buf, len) != len) { req->keep = 0; + req->out_pos = req->out_buf; return 0; } diff --git a/sapi/fpm/fpm/fastcgi.c b/sapi/fpm/fpm/fastcgi.c index 79107c3b41f..8b081b2be12 100644 --- a/sapi/fpm/fpm/fastcgi.c +++ b/sapi/fpm/fpm/fastcgi.c @@ -975,7 +975,7 @@ int fcgi_flush(fcgi_request *req, int close) if (safe_write(req, req->out_buf, len) != len) { req->keep = 0; - req->out_pos = req->out_buf; + req->out_pos = req->out_buf; return 0; } diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 4e7d705c251..d3912de7987 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -669,15 +669,15 @@ void sapi_cgi_log_fastcgi(int level, char *message, size_t len) * - the message is not empty */ if (CGIG(fcgi_logging) && request && message && len > 0) { + int ret; char *buf = malloc(len + 2); - ssize_t ret = 0; memcpy(buf, message, len); memcpy(buf + len, "\n", sizeof("\n")); - ret = fcgi_write(request, FCGI_STDERR, buf, len+1); + ret = fcgi_write(request, FCGI_STDERR, buf, len + 1); free(buf); - if (ret <= 0) { - php_handle_aborted_connection(); - } + if (ret < 0) { + php_handle_aborted_connection(); + } } } /* }}} */ diff --git a/sapi/tests/test006.phpt b/sapi/tests/test006.phpt index 45e37811ef7..5cb211856b7 100644 --- a/sapi/tests/test006.phpt +++ b/sapi/tests/test006.phpt @@ -43,7 +43,6 @@ Content-Type: application/octet-stream phpinfo(); ?> -----------------------------240723202011929-- - --FILE-- Date: Tue, 27 Jan 2015 22:13:30 +0800 Subject: [PATCH 4/4] Update NEWs --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 3708a735615..20c1a55cd44 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,10 @@ . Fixed bug #68731 (finfo_buffer doesn't extract the correct mime with some gifs). (Anatol) +- FPM: + . Fixed bug #68571 (core dump when webserver close the socket). + (redfoxli069 at gmail dot com, Laruence) + - Opcache: . Fixed bug with try blocks being removed when extended_info opcode generation is turned on. (Laruence)