From: Dmitry Stogov Date: Wed, 5 Sep 2007 11:20:45 +0000 (+0000) Subject: Fixed bug #42214 (SoapServer sends clients internal PHP errors) X-Git-Tag: php-5.2.5RC1~216 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e56466edc8e712ec2ffc034f77d72cc00dd7db59;p=php Fixed bug #42214 (SoapServer sends clients internal PHP errors) --- diff --git a/NEWS b/NEWS index 9c24c6204a..cfcea1a2eb 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,7 @@ PHP NEWS breaks). (Dmitry) - Fixed bug #42359 (xsd:list type not parsed). (Dmitry) - Fixed bug #42326 (SoapServer crash). (Dmitry) +- Fixed bug #42214 (SoapServer sends clients internal PHP errors). (Dmitry) - Fixed bug #42086 (SoapServer return Procedure '' not present for WSIBasic compliant wsdl). (Dmitry) diff --git a/ext/soap/php_soap.h b/ext/soap/php_soap.h index 345790463c..73a516c756 100644 --- a/ext/soap/php_soap.h +++ b/ext/soap/php_soap.h @@ -106,6 +106,7 @@ struct _soapService { HashTable *class_map; int features; struct _soapHeader **soap_headers_ptr; + int send_errors; }; #define SOAP_CLASS 1 diff --git a/ext/soap/soap.c b/ext/soap/soap.c index 87d2b43056..e6270a06fc 100644 --- a/ext/soap/soap.c +++ b/ext/soap/soap.c @@ -1035,6 +1035,7 @@ PHP_METHOD(SoapServer, SoapServer) service = emalloc(sizeof(soapService)); memset(service, 0, sizeof(soapService)); + service->send_errors = 1; cache_wsdl = SOAP_GLOBAL(cache); @@ -1099,6 +1100,11 @@ PHP_METHOD(SoapServer, SoapServer) cache_wsdl = Z_LVAL_PP(tmp); } + if (zend_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); + } + } else if (wsdl == NULL) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Invalid arguments. 'uri' option is required in nonWSDL mode."); } @@ -2129,34 +2135,46 @@ static void soap_error_handler(int error_num, const char *error_filename, const char* code = SOAP_GLOBAL(error_code); char buffer[1024]; - int buffer_len; zval *outbuf = NULL; - zval outbuflen; + zval **tmp; + soapServicePtr service; - 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) && + zend_hash_find(Z_OBJPROP_P(SOAP_GLOBAL(error_object)), "service", sizeof("service"), (void **)&tmp) != FAILURE && + (service = (soapServicePtr)zend_fetch_resource(tmp TSRMLS_CC, -1, "service", NULL, 1, le_service)) && + !service->send_errors) { + strcpy(buffer, "Internal Error"); + } else { + int buffer_len; + zval outbuflen; + + INIT_ZVAL(outbuflen); #ifdef va_copy - va_copy(argcopy, args); - buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy); - va_end(argcopy); + va_copy(argcopy, args); + buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy); + va_end(argcopy); #else - buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args); + buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, args); #endif - buffer[sizeof(buffer)-1]=0; - if (buffer_len > sizeof(buffer) - 1 || buffer_len < 0) { - buffer_len = sizeof(buffer) - 1; - } + buffer[sizeof(buffer)-1]=0; + if (buffer_len > sizeof(buffer) - 1 || buffer_len < 0) { + buffer_len = sizeof(buffer) - 1; + } - if (code == NULL) { - code = "Server"; - } - /* Get output buffer and send as fault detials */ - if (php_ob_get_length(&outbuflen TSRMLS_CC) != FAILURE && Z_LVAL(outbuflen) != 0) { - ALLOC_INIT_ZVAL(outbuf); - php_ob_get_buffer(outbuf TSRMLS_CC); - } - php_end_ob_buffer(0, 0 TSRMLS_CC); + /* Get output buffer and send as fault detials */ + if (php_ob_get_length(&outbuflen TSRMLS_CC) != FAILURE && Z_LVAL(outbuflen) != 0) { + ALLOC_INIT_ZVAL(outbuf); + php_ob_get_buffer(outbuf TSRMLS_CC); + } + php_end_ob_buffer(0, 0 TSRMLS_CC); + } INIT_ZVAL(fault_obj); set_soap_fault(&fault_obj, NULL, code, buffer, NULL, outbuf, NULL TSRMLS_CC); fault = 1; 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