]> granicus.if.org Git - php/commitdiff
Fixed bug #39832 (SOAP Server: parameter not matching the WSDL specified type are...
authorDmitry Stogov <dmitry@php.net>
Mon, 18 Dec 2006 14:39:39 +0000 (14:39 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 18 Dec 2006 14:39:39 +0000 (14:39 +0000)
ext/soap/php_encoding.c
ext/soap/tests/bugs/bug39832.phpt [new file with mode: 0755]
ext/soap/tests/bugs/bug39832.wsdl [new file with mode: 0755]

index e7c32c42930f0cce5cded1ae6029c0ff382cf0f9..f689d333a2ad63dab2d230a8941d4b785721de18 100644 (file)
@@ -666,9 +666,15 @@ static zval *to_zval_base64(encodeTypePtr type, xmlNodePtr data)
                if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
                        whiteSpace_collapse(data->children->content);
                        str = (char*)php_base64_decode(data->children->content, strlen((char*)data->children->content), &str_len);
+                       if (!str) {
+                               soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
+                       }
                        ZVAL_STRINGL(ret, str, str_len, 0);
                } else if (data->children->type == XML_CDATA_SECTION_NODE && data->children->next == NULL) {
                        str = (char*)php_base64_decode(data->children->content, strlen((char*)data->children->content), &str_len);
+                       if (!str) {
+                               soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
+                       }
                        ZVAL_STRINGL(ret, str, str_len, 0);
                } else {
                        soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
@@ -705,6 +711,8 @@ static zval *to_zval_hexbin(encodeTypePtr type, xmlNodePtr data)
                                str[i] = (c - 'a' + 10) << 4;
                        } else if (c >= 'A' && c <= 'F') {
                                str[i] = (c - 'A' + 10) << 4;
+                       } else {
+                               soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
                        }
                        c = data->children->content[j++];
                        if (c >= '0' && c <= '9') {
@@ -713,6 +721,8 @@ static zval *to_zval_hexbin(encodeTypePtr type, xmlNodePtr data)
                                str[i] |= c - 'a' + 10;
                        } else if (c >= 'A' && c <= 'F') {
                                str[i] |= c - 'A' + 10;
+                       } else {
+                               soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
                        }
                }
                str[str_len] = '\0';
@@ -825,8 +835,22 @@ static zval *to_zval_double(encodeTypePtr type, xmlNodePtr data)
 
        if (data && data->children) {
                if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
+                       long lval;
+                       double dval;
+
                        whiteSpace_collapse(data->children->content);
-                       ZVAL_DOUBLE(ret, atof((char*)data->children->content));
+                       switch (is_numeric_string((char*)data->children->content, strlen((char*)data->children->content), &lval, &dval, 0)) {
+                               case IS_LONG:
+                                       Z_TYPE_P(ret) = IS_DOUBLE;
+                                       Z_DVAL_P(ret) = lval;
+                                       break;
+                               case IS_DOUBLE:
+                                       Z_TYPE_P(ret) = IS_DOUBLE;
+                                       Z_DVAL_P(ret) = dval;
+                                       break;
+                               default:
+                                       soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
+                       }
                } else {
                        soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
                }
@@ -844,14 +868,21 @@ static zval *to_zval_long(encodeTypePtr type, xmlNodePtr data)
 
        if (data && data->children) {
                if (data->children->type == XML_TEXT_NODE && data->children->next == NULL) {
+                       long lval;
+                       double dval;
+
                        whiteSpace_collapse(data->children->content);
                        errno = 0;
-                       ret->value.lval = strtol((char*)data->children->content, NULL, 0);
-                       if (errno == ERANGE) { /* overflow */
-                               ret->value.dval = zend_strtod((char*)data->children->content, NULL);
-                               ret->type = IS_DOUBLE;
-                       } else {
-                               ret->type = IS_LONG;
+
+                       switch ((Z_TYPE_P(ret) = is_numeric_string((char*)data->children->content, strlen((char*)data->children->content), &lval, &dval, 0))) {
+                               case IS_LONG:
+                                       Z_LVAL_P(ret) = lval;
+                                       break;
+                               case IS_DOUBLE:
+                                       Z_DVAL_P(ret) = dval;
+                                       break;
+                               default:
+                                       soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
                        }
                } else {
                        soap_error0(E_ERROR, "Encoding: Violation of encoding rules");
diff --git a/ext/soap/tests/bugs/bug39832.phpt b/ext/soap/tests/bugs/bug39832.phpt
new file mode 100755 (executable)
index 0000000..010b2e2
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #39832 (SOAP Server: parameter not matching the WSDL specified type are set to 0)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--INI--
+soap.wsdl_cache_enabled=0
+--FILE--
+<?php
+$HTTP_RAW_POST_DATA = <<<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://test.pl"><SOAP-ENV:Body>
+<SOAP-ENV:Test>
+<parameters priority="high">
+<ns1:NetworkErrorCode>1</ns1:NetworkErrorCode>
+</parameters>
+</SOAP-ENV:Test></SOAP-ENV:Body></SOAP-ENV:Envelope>
+EOF;
+
+function Test($x) {
+  return $x->priority;
+}
+
+$x = new SoapServer(dirname(__FILE__)."/bug39832.wsdl");
+$x->addFunction("Test");
+$x->handle();
+?>
+--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: Violation of encoding rules</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
diff --git a/ext/soap/tests/bugs/bug39832.wsdl b/ext/soap/tests/bugs/bug39832.wsdl
new file mode 100755 (executable)
index 0000000..a71f581
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<definitions\r
+               xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"\r
+               xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"\r
+               xmlns:s="http://www.w3.org/2001/XMLSchema"\r
+               xmlns:s0="http://test.pl"\r
+               targetNamespace="http://test.pl"\r
+               xmlns="http://schemas.xmlsoap.org/wsdl/">\r
+       <types>\r
+               <s:schema elementFormDefault="qualified" targetNamespace="http://test.pl">\r
+                       <s:complexType name="MessageInfoType">\r
+                          <s:sequence>\r
+                             <s:element name="NetworkErrorCode" type="s:integer" minOccurs="0"/>\r
+                          </s:sequence>\r
+                          <s:attribute name="priority" type="s0:PriorityType"/>\r
+                       </s:complexType>\r
+                       <s:simpleType name="PriorityType">\r
+                               <s:restriction base="s:integer">\r
+                                       <s:minInclusive value="0"/>\r
+                                       <s:maxInclusive value="3"/>\r
+                          </s:restriction>\r
+                       </s:simpleType> \r
+               </s:schema>\r
+       </types>\r
+\r
+       <message name="TestSoapIn">\r
+               <part name="parameters" type="s0:MessageInfoType" />\r
+       </message>\r
+       <message name="TestSoapOut">\r
+               <part name="parameters" type="s:string" />\r
+       </message>\r
+       <portType name="TestSoap">\r
+               <operation name="Test">\r
+                       <input message="s0:TestSoapIn"/>\r
+                       <output message="s0:TestSoapOut"/>\r
+               </operation>\r
+       </portType>\r
+       <binding name="TestSoap" type="s0:TestSoap">\r
+               <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>\r
+               <operation name="Test">\r
+                       <soap:operation soapAction="http:/Test/Test" style="rpc"/>\r
+                       <input>\r
+                               <soap:body use="literal"/>\r
+                       </input>\r
+                       <output>\r
+                               <soap:body use="literal"/>\r
+                       </output>\r
+               </operation>\r
+       </binding>\r
+       <service name="Test">\r
+               <port name="TestSoapPort" binding="s0:TestSoap">\r
+                       <soap:address location="http://localhost/server.php"/>\r
+               </port>\r
+       </service>\r
+</definitions>\r