PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Web Services » XML_RPC » Bug #8560

Bad conversion of invalid ints in structs

Details

Submitted2006-08-25 15:10 UTC
Fromheiko dot hund at schlund dot de
Assigneddanielc
StatusBogus
PackageXML_RPC
PHP Version4.4.2
OSLinux 2.6.16 i386
Roadmaps(Not assigned)

Comments

[2006-08-25 15:10 UTC] heiko dot hund at schlund dot de

Description:
------------
If a client submits an invalid integer value within a
struct the server does not recognize it as bad but instead
converts it to the value 102.

I appended two testscripts that show this behaviour.

Test script:
---------------
----client.php--------------------------------------------
<?php

include_once("XML/RPC.php");

$client = new XML_RPC_Client('/server.php', 'localhost');
$response = $client->send(
new XML_RPC_Message(
"test",
array(
new XML_RPC_Value(
array(
'testInt' => new XML_RPC_Value('-1aaa', 'int') // <= BAD!
), 'struct'
)
)
)
);

?>

----server.php--------------------------------------------
<?php

include_once("XML/Server.php");

$server = new XML_RPC_Server(
array(
'test' => array(
'function' => 'doTest'
)
), 1, 0
);

function doTest($params)
{
$struct = $params->getParam(0);
$member = $struct->structmem('testInt');
return new XML_RPC_Response(new XML_RPC_Value($member->scalarval(), 'string'));
}

?>

Actual result:
--------------
<methodResponse>
<params>
<param>
<value><string>102</string></value>
</param>
</params>
</methodResponse>

[2006-08-28 09:43 UTC] heiko dot hund at schlund dot de

I did some debugging on my own resulting in a patch
that 'works for me'[tm]:

--- RPC.php Mon Aug 28 11:40:40 2006
+++ RPC.php.new Mon Aug 28 11:40:27 2006
@@ -465,7 +465,8 @@
if (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?
[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) {
XML_RPC_Base::raiseError('Non-numeric
value received in INT or DOUBLE',

XML_RPC_ERROR_NON_NUMERIC_FOUND);
- $XML_RPC_xh[$parser]['value'] =
XML_RPC_ERROR_NON_NUMERIC_FOUND;
+ $XML_RPC_xh[$parser]['isf'] =
XML_RPC_ERROR_NON_NUMERIC_FOUND;
+ $XML_RPC_xh[$parser]['isf_reason']
= 'Non-numeric value received in INT or DOUBLE';
} else {
// it's ok, add it on
$XML_RPC_xh[$parser]['value'] =
$XML_RPC_xh[$parser]['ac'];

[2006-08-28 09:48 UTC] heiko dot hund at schlund dot de

Oh my! Look at the nasty linebreaks. If you want a more
readable patch I'll be happy to mail it to you.

[2006-10-30 17:17 UTC] heiko dot hund at schlund dot de

Thanks for the reply. I still think that this is a bug or
at least something that should be improved.

The odd thing is that an malformed integer that is not
member of a struct is reported by the framework in a
<fault> message sent to the caller, while an integer as a
struct member is not. The latter has to be manually
checked within the server method.

new XML_RPC_Message(
"test",
array(
new XML_RPC_Value('-1aaa', 'int'),
new XML_RPC_Value(
array(
'testInt' => new XML_RPC_Value('-1aaa', 'int')
), 'struct'
)
)
)

For the request fragment above the first malformed integer
would lead to a fault directly, while the second would not
and has to be manually checked for.

I think it would be straight forward to handle them both
the same way (the patch does that), or is there a reason
for this behavior I'm not aware of?