From 74c08d50d57a5fb9ed466873bdf730c5c76e51d9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Wed, 5 Sep 2007 11:21:01 +0000 Subject: [PATCH] Fixed bug #42214 (SoapServer sends clients internal PHP errors) --- ext/soap/php_soap.h | 1 + ext/soap/soap.c | 47 +++++++++++++++++++++---------- ext/soap/tests/bugs/bug42214.phpt | 24 ++++++++++++++++ 3 files changed, 57 insertions(+), 15 deletions(-) create mode 100755 ext/soap/tests/bugs/bug42214.phpt diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index 9ded7d2e5a..1bd50a6bc2 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -105,6 +105,7 @@ typedef struct _soap_server_object { int type; char *actor; struct _soapHeader **soap_headers_ptr; + int send_errors; } soap_server_object; typedef struct _soap_client_object { diff --git a/ext/soap/soap.c b/ext/soap/soap.c index ec7a230438..d7043d279f 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1382,6 +1382,7 @@ PHP_METHOD(SoapServer, SoapServer) } service = (soap_server_object*)zend_object_store_get_object(this_ptr TSRMLS_CC); + service->send_errors = 1; cache_wsdl = SOAP_GLOBAL(cache); @@ -1457,6 +1458,11 @@ PHP_METHOD(SoapServer, SoapServer) Z_TYPE_PP(tmp) == IS_LONG) { cache_wsdl = Z_LVAL_PP(tmp); } + + if (zend_ascii_hash_find(ht, "send_errors", sizeof("send_errors"), (void**)&tmp) == SUCCESS && + (Z_TYPE_PP(tmp) == IS_BOOL || Z_TYPE_PP(tmp) == IS_LONG)) { + service->send_errors = Z_LVAL_PP(tmp); + } } if (wsdl == NULL && service->uri == NULL) { @@ -2504,30 +2510,41 @@ static void soap_error_handler(int error_num, const char *error_filename, const error_num == E_PARSE) { char* code = SOAP_GLOBAL(error_code); + soap_server_object *server; char *buffer; - int buffer_len; zval *outbuf = NULL; - zval outbuflen; - INIT_ZVAL(outbuflen); + if (code == NULL) { + code = "Server"; + } + + if (SOAP_GLOBAL(error_object) && + Z_TYPE_P(SOAP_GLOBAL(error_object)) == IS_OBJECT && + instanceof_function(Z_OBJCE_P(SOAP_GLOBAL(error_object)), soap_server_class_entry TSRMLS_CC) && + (server = (soap_server_object*)zend_object_store_get_object(SOAP_GLOBAL(error_object) TSRMLS_CC)) && + !server->send_errors) { + buffer = estrdup("Internal Error"); + } else { + int buffer_len; + zval outbuflen; + + INIT_ZVAL(outbuflen); #ifdef va_copy - va_copy(argcopy, args); - buffer_len = vspprintf(&buffer, 0, format, argcopy); - va_end(argcopy); + va_copy(argcopy, args); + buffer_len = vspprintf(&buffer, 0, format, argcopy); + va_end(argcopy); #else - buffer_len = vspprintf(&buffer, 0, format, args); + buffer_len = vspprintf(&buffer, 0, format, args); #endif - if (code == NULL) { - code = "Server"; - } - /* Get output buffer and send as fault detials */ - if (php_output_get_length(&outbuflen TSRMLS_CC) != FAILURE && Z_LVAL(outbuflen) != 0) { - ALLOC_INIT_ZVAL(outbuf); - php_output_get_contents(outbuf TSRMLS_CC); + /* Get output buffer and send as fault detials */ + if (php_output_get_length(&outbuflen TSRMLS_CC) != FAILURE && Z_LVAL(outbuflen) != 0) { + ALLOC_INIT_ZVAL(outbuf); + php_output_get_contents(outbuf TSRMLS_CC); + } + php_output_discard(TSRMLS_C); } - php_output_discard(TSRMLS_C); INIT_ZVAL(fault_obj); set_soap_fault(&fault_obj, NULL, code, buffer, NULL, outbuf, NULL TSRMLS_CC); diff --git a/ext/soap/tests/bugs/bug42214.phpt b/ext/soap/tests/bugs/bug42214.phpt new file mode 100755 index 0000000000..2f85686842 --- /dev/null +++ b/ext/soap/tests/bugs/bug42214.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #42214 SoapServer sends clients internal PHP errors +--SKIPIF-- + +--FILE-- + + +EOF; + +function test() { + $a = $b; + obvious_error(); // will cause an error +} + +$server = new SoapServer(NULL, array('uri' =>'http://localhost/server.php', + 'send_errors'=>0)); +$server->addFunction('test'); +$server->handle($request); +?> +--EXPECT-- + +SOAP-ENV:ServerInternal Error -- 2.40.0