Skip to content

Commit f6079e3

Browse files
committed
Fix #77141: Signedness issue in SOAP when precision=-1
According to php_gcvt(), we assume at most 17 fractional digits for negative precision.
1 parent 625f614 commit f6079e3

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PHP NEWS
1111

1212
- SOAP:
1313
. Fixed bug #76348 (WSDL_CACHE_MEMORY causes Segmentation fault). (cmb)
14+
. Fixed bug #77141 (Signedness issue in SOAP when precision=-1). (cmb)
1415

1516
08 Nov 2018, PHP 7.1.24
1617

ext/soap/php_encoding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ static xmlNodePtr to_xml_double(encodeTypePtr type, zval *data, int style, xmlNo
10981098

10991099
ZVAL_DOUBLE(&tmp, zval_get_double(data));
11001100

1101-
str = (char *) safe_emalloc(EG(precision), 1, MAX_LENGTH_OF_DOUBLE + 1);
1101+
str = (char *) safe_emalloc(EG(precision) >= 0 ? EG(precision) : 17, 1, MAX_LENGTH_OF_DOUBLE + 1);
11021102
php_gcvt(Z_DVAL(tmp), EG(precision), '.', 'E', str);
11031103
xmlNodeSetContentLen(ret, BAD_CAST(str), strlen(str));
11041104
efree(str);

ext/soap/tests/bugs/bug77141.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #77141 (Signedness issue in SOAP when precision=-1)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('soap')) die('skip soap extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$soap = new \SoapClient(
10+
null,
11+
array(
12+
'location' => "http://localhost/soap.php",
13+
'uri' => "http://localhost/",
14+
'style' => SOAP_RPC,
15+
'trace' => true,
16+
'exceptions' => false,
17+
)
18+
);
19+
ini_set('precision', -1);
20+
$soap->call(1.1);
21+
echo $soap->__getLastRequest();
22+
?>
23+
===DONE===
24+
--EXPECT--
25+
<?xml version="1.0" encoding="UTF-8"?>
26+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:call><param0 xsi:type="xsd:float">1.1</param0></ns1:call></SOAP-ENV:Body></SOAP-ENV:Envelope>
27+
===DONE===

0 commit comments

Comments
 (0)