]> granicus.if.org Git - php/commitdiff
Fixed bug #42214 (SoapServer sends clients internal PHP errors)
authorDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 11:21:01 +0000 (11:21 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 11:21:01 +0000 (11:21 +0000)
ext/soap/php_soap.h
ext/soap/soap.c
ext/soap/tests/bugs/bug42214.phpt [new file with mode: 0755]

index 9ded7d2e5ac5d1d3f558a37d55b39db0417bfbd0..1bd50a6bc2883242f6184ceabaa439dcb1c6456b 100644 (file)
@@ -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 {
index ec7a230438897d356028c9c248137906b1964a3e..d7043d279f77c9601bc5cd2369849509742d304c 100644 (file)
@@ -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 (executable)
index 0000000..2f85686
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Bug #42214 SoapServer sends clients internal PHP errors
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$request = <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/server.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:test/></SOAP-ENV:Body></SOAP-ENV:Envelope>
+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--
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>Internal Error</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>