dmitry          Wed Sep  5 10:18:38 2007 UTC

  Modified files:              
    /php-src/ext/soap   soap.c 
    /php-src/ext/soap/tests/bugs        bug42488.phpt 
  Log:
  Fixed bug #42488 (SoapServer reports an encoding error and the error itself 
breaks).
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/soap/soap.c?r1=1.228&r2=1.229&diff_format=u
Index: php-src/ext/soap/soap.c
diff -u php-src/ext/soap/soap.c:1.228 php-src/ext/soap/soap.c:1.229
--- php-src/ext/soap/soap.c:1.228       Fri Aug 31 10:48:57 2007
+++ php-src/ext/soap/soap.c     Wed Sep  5 10:18:37 2007
@@ -17,7 +17,7 @@
   |          Dmitry Stogov <[EMAIL PROTECTED]>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: soap.c,v 1.228 2007/08/31 10:48:57 dmitry Exp $ */
+/* $Id: soap.c,v 1.229 2007/09/05 10:18:37 dmitry Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -343,13 +343,49 @@
                        if (n >= 0) {
                                efree(str);
                                str = estrdup((char*)xmlBufferContent(out));
-                       } 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);
                }
        }
        return str;
@@ -386,13 +422,49 @@
                                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);
                }
        }
        if (len) {
http://cvs.php.net/viewvc.cgi/php-src/ext/soap/tests/bugs/bug42488.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/soap/tests/bugs/bug42488.phpt
diff -u /dev/null php-src/ext/soap/tests/bugs/bug42488.phpt:1.2
--- /dev/null   Wed Sep  5 10:18:38 2007
+++ php-src/ext/soap/tests/bugs/bug42488.phpt   Wed Sep  5 10:18:38 2007
@@ -0,0 +1,23 @@
+--TEST--
+Bug #42488 (SoapServer reports an encoding error and the error itself breaks)
+--SKIPIF--
+<?php if (unicode_semantics()) die('skip unicode.semantics=on'); ?>
+<?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

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to