]> 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:20:45 +0000 (11:20 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 11:20:45 +0000 (11:20 +0000)
NEWS
ext/soap/php_soap.h
ext/soap/soap.c
ext/soap/tests/bugs/bug42214.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 9c24c6204ae7fc0beff4106284fb5e209c0e6d7e..cfcea1a2eb981f13fb5382108258bb4f5c2af010 100644 (file)
--- 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)
 
index 345790463c73d83d610402709ce6a4acd945da99..73a516c756735485f36d153f93fc6c071f2c19e1 100644 (file)
@@ -106,6 +106,7 @@ struct _soapService {
        HashTable *class_map;
        int        features;
        struct _soapHeader **soap_headers_ptr;
+       int send_errors;
 };
 
 #define SOAP_CLASS 1
index 87d2b43056c88bd1f7cac235245da6f4af83f428..e6270a06fc310373ede401b714ace58ab7cce7da 100644 (file)
@@ -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 (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>