From 26499be68f1a9d593c14b4ca848bbbbc8b2876d9 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 10 Jul 2006 10:33:43 +0000 Subject: [PATCH] Fixed bug #38055 (Wrong interpretation of boolean parameters) --- NEWS | 1 + ext/soap/php_encoding.c | 21 +++++-------- ext/soap/tests/bugs/bug38055.phpt | 39 ++++++++++++++++++++++++ ext/soap/tests/bugs/bug38055.wsdl | 49 +++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 14 deletions(-) create mode 100755 ext/soap/tests/bugs/bug38055.phpt create mode 100755 ext/soap/tests/bugs/bug38055.wsdl diff --git a/NEWS b/NEWS index d939babb2c..6c717876e8 100644 --- a/NEWS +++ b/NEWS @@ -82,6 +82,7 @@ PHP NEWS - Fixed memory leaks in openssl streams context options. (Pierre) - Fixed handling of extremely long paths inside tempnam() function. (Ilia) +- Fixed bug #38055 (Wrong interpretation of boolean parameters). (Dmitry) - Fixed bug #38019 (segfault extending mysqli class). (Dmitry) - Fixed bug #38005 (SoapFault faultstring doesn't follow encoding rules). (Dmitry) diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 8d574c2225..f0a4fdfd80 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -962,8 +962,13 @@ static zval *to_zval_bool(encodeTypePtr type, xmlNodePtr data) stricmp(data->children->content,"t") == 0 || strcmp(data->children->content,"1") == 0) { ZVAL_BOOL(ret, 1); - } else { + } else if (stricmp(data->children->content,"false") == 0 || + stricmp(data->children->content,"f") == 0 || + strcmp(data->children->content,"0") == 0) { ZVAL_BOOL(ret, 0); + } else { + ZVAL_STRING(ret, data->children->content, 1); + convert_to_boolean(ret); } } else { soap_error0(E_ERROR, "Encoding: Violation of encoding rules"); @@ -977,29 +982,17 @@ static zval *to_zval_bool(encodeTypePtr type, xmlNodePtr data) static xmlNodePtr to_xml_bool(encodeTypePtr type, zval *data, int style, xmlNodePtr parent) { xmlNodePtr ret; - zval tmp; ret = xmlNewNode(NULL,"BOGUS"); xmlAddChild(parent, ret); FIND_ZVAL_NULL(data, ret, style); - if (Z_TYPE_P(data) != IS_BOOL) { - tmp = *data; - zval_copy_ctor(&tmp); - convert_to_boolean(data); - data = &tmp; - } - - if (data->value.lval == 1) { + if (zend_is_true(data)) { xmlNodeSetContent(ret, "true"); } else { xmlNodeSetContent(ret, "false"); } - if (data == &tmp) { - zval_dtor(&tmp); - } - if (style == SOAP_ENCODED) { set_ns_and_type(ret, type); } diff --git a/ext/soap/tests/bugs/bug38055.phpt b/ext/soap/tests/bugs/bug38055.phpt new file mode 100755 index 0000000000..07e7e1e0bd --- /dev/null +++ b/ext/soap/tests/bugs/bug38055.phpt @@ -0,0 +1,39 @@ +--TEST-- +Bug #38055 (Wrong interpretation of boolean parameters) +--SKIPIF-- + +--FILE-- +boolA; + $g2 = $param->boolB; + return 1; +} + +class TestSoapClient extends SoapClient { + function __construct($wsdl) { + parent::__construct($wsdl); + $this->server = new SoapServer($wsdl); + $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(dirname(__FILE__).'/bug38055.wsdl'); +$boolA = 1; +$boolB = '1'; +$res = $client->Test(array('boolA'=>$boolA, 'boolB'=>$boolB)); +var_dump($g1); +var_dump($g2); +?> +--EXPECT-- +bool(true) +bool(true) diff --git a/ext/soap/tests/bugs/bug38055.wsdl b/ext/soap/tests/bugs/bug38055.wsdl new file mode 100755 index 0000000000..f8935477f1 --- /dev/null +++ b/ext/soap/tests/bugs/bug38055.wsdl @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.40.0