]> granicus.if.org Git - php/commitdiff
Fixed bug #38005 (SoapFault faultstring doesn't follow encoding rules)
authorDmitry Stogov <dmitry@php.net>
Mon, 10 Jul 2006 07:41:33 +0000 (07:41 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 10 Jul 2006 07:41:33 +0000 (07:41 +0000)
NEWS
ext/soap/php_packet_soap.c
ext/soap/soap.c
ext/soap/tests/bugs/bug38005.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index d48ed47008223443ee94a6869a2a92936ac1b749..32098c9ae40af3308e01d00cf36ccb16cdd2c250 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -82,7 +82,9 @@ PHP                                                                        NEWS
 
 - Fixed memory leaks in openssl streams context options. (Pierre)
 - Fixed handling of extremely long paths inside tempnam() function. (Ilia)
-- Fixed bug #38004 Parameters in SoapServer are decoded twice. (Dmitry)
+- Fixed bug #38005 (SoapFault faultstring doesn't follow encoding rules).
+  (Dmitry)
+- Fixed bug #38004 (Parameters in SoapServer are decoded twice). (Dmitry)
 - Fixed bug #38003 (in classes inherited from MySQLi it's possible to call 
   private constructors from invalid context). (Tony)
 - Fixed bug #37987 (invalid return of file_exists() in safe mode). (Ilia)
index 4fb45a6413e72a1cfee2c6e4ec4d58bdbbba0265..92d9df5161f9605ce5d8d9be42ef610ab7d3ebcf 100644 (file)
@@ -191,12 +191,16 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
 
                        tmp = get_node(fault->children,"faultstring");
                        if (tmp != NULL && tmp->children != NULL) {
-                               faultstring = tmp->children->content;
+                               zval *zv = master_to_zval(get_conversion(IS_STRING), tmp);
+                               faultstring = Z_STRVAL_P(zv);
+                               FREE_ZVAL(zv);
                        }
 
                        tmp = get_node(fault->children,"faultactor");
                        if (tmp != NULL && tmp->children != NULL) {
-                               faultactor = tmp->children->content;
+                               zval *zv = master_to_zval(get_conversion(IS_STRING), tmp);
+                               faultactor = Z_STRVAL_P(zv);
+                               FREE_ZVAL(zv);
                        }
 
                        tmp = get_node(fault->children,"detail");
@@ -217,7 +221,9 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
                                /* TODO: lang attribute */
                                tmp = get_node(tmp->children,"Text");
                                if (tmp != NULL && tmp->children != NULL) {
-                                       faultstring = tmp->children->content;
+                                       zval *zv = master_to_zval(get_conversion(IS_STRING), tmp);
+                                       faultstring = Z_STRVAL_P(zv);
+                                       FREE_ZVAL(zv);
                                }
                        }
 
@@ -227,6 +233,12 @@ int parse_packet_soap(zval *this_ptr, char *buffer, int buffer_size, sdlFunction
                        }
                }
                add_soap_fault(this_ptr, faultcode, faultstring, faultactor, details TSRMLS_CC);
+               if (faultstring) {
+                       efree(faultstring);
+               }
+               if (faultactor) {
+                       efree(faultactor);
+               }
 #ifdef ZEND_ENGINE_2
                if (details) {
                        details->refcount--;
index f8926da0eafd2eab66a292d4d2f8e111b519daee..374447365edd21b75349dcbe2c72f38a0c20b915 100644 (file)
@@ -3729,20 +3729,12 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function
                                efree(str);
                        }
                        if (zend_hash_find(prop, "faultstring", sizeof("faultstring"), (void**)&tmp) == SUCCESS) {
-                               int new_len;
-                               xmlNodePtr node = xmlNewNode(NULL, "faultstring");
-                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
-                               xmlAddChild(param, node);
-                               xmlNodeSetContentLen(node, str, new_len);
-                               efree(str);
+                               xmlNodePtr node = master_to_xml(get_conversion(IS_STRING), *tmp, SOAP_LITERAL, param);
+                               xmlNodeSetName(node, "faultstring");
                        }
                        if (zend_hash_find(prop, "faultactor", sizeof("faultactor"), (void**)&tmp) == SUCCESS) {
-                               int new_len;
-                               xmlNodePtr node = xmlNewNode(NULL, "faultactor");
-                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
-                               xmlAddChild(param, node);
-                               xmlNodeSetContentLen(node, str, new_len);
-                               efree(str);
+                               xmlNodePtr node = master_to_xml(get_conversion(IS_STRING), *tmp, SOAP_LITERAL, param);
+                               xmlNodeSetName(node, "faultactor");
                        }
                        detail_name = "detail";
                } else {
@@ -3760,12 +3752,10 @@ static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function
                                efree(str);
                        }
                        if (zend_hash_find(prop, "faultstring", sizeof("faultstring"), (void**)&tmp) == SUCCESS) {
-                               int new_len;
                                xmlNodePtr node = xmlNewChild(param, ns, "Reason", NULL);
-                               char *str = php_escape_html_entities(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp), &new_len, 0, 0, NULL TSRMLS_CC);
-                               node = xmlNewChild(node, ns, "Text", NULL);
-                               xmlNodeSetContentLen(node, str, new_len);
-                               efree(str);
+                               node = master_to_xml(get_conversion(IS_STRING), *tmp, SOAP_LITERAL, node);
+                               xmlNodeSetName(node, "Text");
+                               xmlSetNs(node, ns);
                        }
                        detail_name = SOAP_1_2_ENV_NS_PREFIX":Detail";
                }
diff --git a/ext/soap/tests/bugs/bug38005.phpt b/ext/soap/tests/bugs/bug38005.phpt
new file mode 100755 (executable)
index 0000000..d15becc
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+Bug #38005 (SoapFault faultstring doesn't follow encoding rules)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function Test($param) {
+       return new SoapFault('Test', 'This is our fault: Ä');
+}
+
+class TestSoapClient extends SoapClient {
+  function __construct($wsdl, $opt) {
+    parent::__construct($wsdl, $opt);
+    $this->server = new SoapServer($wsdl, $opt);
+    $this->server->addFunction('Test');
+  }
+
+  function __doRequest($request, $location, $action, $version) {
+    ob_start();
+    $this->server->handle($request);
+    $response = ob_get_contents();
+    ob_end_clean();
+    return $response;
+  }
+}
+
+$client = new TestSoapClient(NULL, array(
+    'encoding' => 'ISO-8859-1',
+       'uri' => "test://",
+       'location' => "test://",
+       'soap_version'=>SOAP_1_2,
+       'trace'=>1, 
+       'exceptions'=>0));
+$res = $client->Test();
+echo($res->faultstring."\n");
+echo($client->__getLastResponse());
+?>
+--EXPECT--
+This is our fault: Ä
+<?xml version="1.0" encoding="UTF-8"?>
+<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Body><env:Fault><env:Code><env:Value>Test</env:Value></env:Code><env:Reason><env:Text>This is our fault: Ä</env:Text></env:Reason></env:Fault></env:Body></env:Envelope>