]> granicus.if.org Git - php/commitdiff
Fixed bug #42488 (SoapServer reports an encoding error and the error itself breaks).
authorDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 10:18:23 +0000 (10:18 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 5 Sep 2007 10:18:23 +0000 (10:18 +0000)
NEWS
ext/soap/php_encoding.c
ext/soap/tests/bugs/bug42488.phpt [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 77dd9b23d3ec53af1a609ec017da5c1d7ece6675..9c24c6204ae7fc0beff4106284fb5e209c0e6d7e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ PHP                                                                        NEWS
   (Hannes)
 - Fixed bug #42468 (Write lock on file_get_contents fails when using a 
   compression stream). (Ilia)
+- Fixed bug #42488 (SoapServer reports an encoding error and the error itself
+  breaks). (Dmitry)
 - Fixed bug #42359 (xsd:list type not parsed). (Dmitry)
 - Fixed bug #42326 (SoapServer crash). (Dmitry)
 - Fixed bug #42086 (SoapServer return Procedure '' not present for WSIBasic
index 65e703d5d21ffc0c640f039dd4ab07c0d7eaf672..8354f87ace9078a2a544ba5c7cb63387c06e9c35 100644 (file)
@@ -864,13 +864,50 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
                        efree(str);
                        str = estrdup((char*)xmlBufferContent(out));
                        new_len = n;
-               } else if (!php_libxml_xmlCheckUTF8(BAD_CAST(str))) {
-                       soap_error1(E_ERROR,  "Encoding: string '%s' is not a valid utf-8 string", str);
                }
                xmlBufferFree(out);
                xmlBufferFree(in);
-       } else if (!php_libxml_xmlCheckUTF8(BAD_CAST(str))) {
-               soap_error1(E_ERROR,  "Encoding: string '%s' is not a valid utf-8 string", str);
+       }
+
+       if (!php_libxml_xmlCheckUTF8(BAD_CAST(str))) {
+               char *err = emalloc(new_len + 8);
+               char c;
+               int i;
+               
+               memcpy(err, str, new_len+1);
+               for (i = 0; (c = err[i++]);) {
+                       if ((c & 0x80) == 0) {
+                       } else if ((c & 0xe0) == 0xc0) {
+                               if ((err[i] & 0xc0) != 0x80) {
+                                       break;
+                               }
+                               i++;
+                       } else if ((c & 0xf0) == 0xe0) {
+                               if ((err[i] & 0xc0) != 0x80 || (err[i+1] & 0xc0) != 0x80) {
+                                       break;
+                               }
+                               i += 2;
+                       } else if ((c & 0xf8) == 0xf0) {
+                               if ((err[i] & 0xc0) != 0x80 || (err[i+1] & 0xc0) != 0x80 || (err[i+2] & 0xc0) != 0x80) {
+                                       break;
+                               }
+                               i += 3;
+                       } else {
+                               break;
+                       }
+               }
+               if (c) {
+                       err[i-1] = '\\';
+                       err[i++] = 'x';
+                       err[i++] = ((unsigned char)c >> 4) + ((((unsigned char)c >> 4) > 9) ? ('a' - 10) : '0');
+                       err[i++] = (c & 15) + (((c & 15) > 9) ? ('a' - 10) : '0');
+                       err[i++] = '.';
+                       err[i++] = '.';
+                       err[i++] = '.';
+                       err[i++] = 0;
+               }
+
+               soap_error1(E_ERROR,  "Encoding: string '%s' is not a valid utf-8 string", err);
        }
 
        text = xmlNewTextLen(BAD_CAST(str), new_len);
diff --git a/ext/soap/tests/bugs/bug42488.phpt b/ext/soap/tests/bugs/bug42488.phpt
new file mode 100755 (executable)
index 0000000..4069c9f
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #42488 (SoapServer reports an encoding error and the error itself breaks)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--INI--
+soap.wsdl_cache_enabled=0
+--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="test:\" 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:getBadUTF/></SOAP-ENV:Body></SOAP-ENV:Envelope>
+EOF;
+$soap = new SoapServer(NULL, array('uri'=>'test://'));
+function getBadUTF(){
+    return "stuff\x93thing";
+}
+$soap->addFunction('getBadUTF');
+$soap->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>SOAP-ERROR: Encoding: string 'stuff\x93...' is not a valid utf-8 string</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
\ No newline at end of file