ID:               27446
 Comment by:       kawai at apache dot org
 Reported By:      tomy at envox dot hr
 Status:           Verified
 Bug Type:         XMLRPC-EPI related
 Operating System: *
 PHP Version:      5CVS, 4CVS (2004-03-01)
 New Comment:

I also hit this bug in my own server. I analyzed the bug, and created a
patch for this:


--- php-5.2.6/ext/xmlrpc/xmlrpc-epi-php.c       Mon Dec 31 16:20:14 2007
+++ xmlrpc-epi-php.c    Fri May  2 22:41:30 2008
@@ -859,6 +859,20 @@
    zval* callback_params[3];
    TSRMLS_FETCH();
    
+       const char* methodname = XMLRPC_RequestGetMethodName(xRequest);
+       zval **php_function;
+       if (!methodname) { methodname = ""; }
+       Z_STRVAL_P(pData->xmlrpc_method) = estrdup(methodname);
+       Z_STRLEN_P(pData->xmlrpc_method) = strlen(methodname);
+       Z_TYPE_P(pData->xmlrpc_method) = IS_STRING;
+       pData->php_executed = 0;
+       if(zend_hash_find(Z_ARRVAL_P(pData->server->method_map),
+                      Z_STRVAL_P(pData->xmlrpc_method), 
+                      Z_STRLEN_P(pData->xmlrpc_method) + 1, 
+                      (void**)&php_function) == SUCCESS) {
+               pData->php_function = *php_function;
+       }
+   
    /* convert xmlrpc to native php types */
    xmlrpc_params = XMLRPC_to_PHP(XMLRPC_RequestGetData(xRequest));
 
@@ -876,7 +890,7 @@
 
    zval_ptr_dtor(&xmlrpc_params);
 
-   return NULL;
+   return PHP_to_XMLRPC(pData->return_data TSRMLS_CC);
 }
 
 /* called by the C server when it first receives an introspection
request.  We pass this on to
@@ -1017,7 +1031,6 @@
    Parses XML requests and call methods */
 PHP_FUNCTION(xmlrpc_server_call_method)
 {
-       xmlrpc_callback_data data = {0};
        XMLRPC_REQUEST xRequest;
        STRUCT_XMLRPC_REQUEST_INPUT_OPTIONS input_opts;
        xmlrpc_server_data* server;
@@ -1048,8 +1061,8 @@
 
                if(xRequest) {
                        const char* methodname = 
XMLRPC_RequestGetMethodName(xRequest);
-                       zval **php_function;
-                       XMLRPC_VALUE xAnswer = NULL;
+                       
+                       xmlrpc_callback_data data = {0};
                        MAKE_STD_ZVAL(data.xmlrpc_method); /* init. very 
important.  spent
a frustrating day finding this out. */
                        MAKE_STD_ZVAL(data.return_data);
                        Z_TYPE_P(data.return_data) = IS_NULL;  /* in case value 
is never
init'd, we don't dtor to think it is a string or something */
@@ -1060,26 +1073,15 @@
                        }
             
                        /* setup some data to pass to the callback function */
-                       Z_STRVAL_P(data.xmlrpc_method) = estrdup(methodname);
-                       Z_STRLEN_P(data.xmlrpc_method) = strlen(methodname);
-                       Z_TYPE_P(data.xmlrpc_method) = IS_STRING;
                        data.caller_params = *caller_params;
                        data.php_executed = 0;
                        data.server = server;
 
-                       /* check if the called method has been previous 
registered */
-                       if(zend_hash_find(Z_ARRVAL_P(server->method_map),
-                              Z_STRVAL_P(data.xmlrpc_method), 
-                              Z_STRLEN_P(data.xmlrpc_method) + 1, 
-                              (void**)&php_function) == SUCCESS) {
-
-                               data.php_function = *php_function;
-                       }
-
                        /* We could just call the php method directly ourselves 
at this
point, but we do this 
                         * with a C callback in case the xmlrpc library ever 
implements
some cool usage stats,
                         * or somesuch.
                         */
+                       XMLRPC_VALUE xAnswer = NULL;
                        xAnswer = XMLRPC_ServerCallMethod(server->server_ptr, 
xRequest,
&data);
                        if(xAnswer && out.b_php_out) {
                                zval_dtor(data.return_data);
@@ -1086,7 +1088,9 @@
                                FREE_ZVAL(data.return_data);
                                data.return_data = XMLRPC_to_PHP(xAnswer);
                        } else if(data.php_executed && !out.b_php_out) {
-                               xAnswer = PHP_to_XMLRPC(data.return_data 
TSRMLS_CC);
+                               if(!xAnswer){
+                                       xAnswer = 
PHP_to_XMLRPC(data.return_data TSRMLS_CC);
+                               }
                        }
 
                        /* should we return data as xml? */


Previous Comments:
------------------------------------------------------------------------

[2004-03-15 23:35:42] [EMAIL PROTECTED]

It crashes, here's the backtrace with latest CVS checkout:

0x404b9e8c in call_user_function_ex (function_table=0x80b8868,
object_pp=0x0, function_name=0x0,
    retval_ptr_ptr=0xbfffc954, param_count=3, params=0x8218104,
no_separation=1, symbol_table=0x0)
    at /usr/src/web/php/php4/Zend/zend_execute_API.c:445
445             if (function_name->type==IS_ARRAY) { /* assume
array($obj, $name) couple */
(gdb)
(gdb) bt
#0  0x404b9e8c in call_user_function_ex (function_table=0x80b8868,
object_pp=0x0, function_name=0x0,
    retval_ptr_ptr=0xbfffc954, param_count=3, params=0x8218104,
no_separation=1, symbol_table=0x0)
    at /usr/src/web/php/php4/Zend/zend_execute_API.c:445
#1  0x404b9d7e in call_user_function (function_table=0x80b8868,
object_pp=0x0, function_name=0x0, retval_ptr=0x8219d0c,
    param_count=3, params=0xbfffc990) at
/usr/src/web/php/php4/Zend/zend_execute_API.c:409
#2  0x404774b0 in php_xmlrpc_callback (server=0x821b008,
xRequest=0x8219fa8, data=0xbfffcae0)
    at /usr/src/web/php/php4/ext/xmlrpc/xmlrpc-epi-php.c:882
#3  0x404800fc in XMLRPC_ServerCallMethod (server=0x821b008,
request=0x8219fa8, userData=0xbfffcae0)
    at /usr/src/web/php/php4/ext/xmlrpc/libxmlrpc/xmlrpc.c:2522
#4  0x4047b147 in xsm_system_multicall_cb (server=0x821b008,
input=0x8219f48, userData=0xbfffcae0)
    at /usr/src/web/php/php4/ext/xmlrpc/libxmlrpc/system_methods.c:337
#5  0x404800fc in XMLRPC_ServerCallMethod (server=0x821b008,
request=0x8219f48, userData=0xbfffcae0)
    at /usr/src/web/php/php4/ext/xmlrpc/libxmlrpc/xmlrpc.c:2522
#6  0x40477b5d in zif_xmlrpc_server_call_method (ht=3,
return_value=0x8219c0c, this_ptr=0x0, return_value_used=1)
    at /usr/src/web/php/php4/ext/xmlrpc/xmlrpc-epi-php.c:1103
#7  0x404d59a8 in execute (op_array=0x8214f1c) at
/usr/src/web/php/php4/Zend/zend_execute.c:1621


------------------------------------------------------------------------

[2004-03-01 07:56:40] tomy at envox dot hr

Description:
------------
When building xmlrpc server, system.multiCall method does not work with
my method but works with "built-in" methods such as system.listMethods
or system.methodHelp.

I have tested this on latest CVS snapshots both for PHP4 and PHP5, on
Suse 8.2.

In following example I have submitted http request sent to server whose
code is presented in "Reproduce code".
I do not get nay response and HTTP connection to server is dropped.

Calling "built-in" methods such as system.listMethods or
system.methodHelp using system.multiCall works OK.
Calling my method ("contact.select") in a straight fashion (without
system.multiCall) works OK here is request and response with headers:

POST /xmlrpc_server.php HTTP/1.0
Content-Type: text/xml
Content-Length: 317

<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>contact.select</methodName>
<params>
 <param>
  <value>
   <struct>
    <member>
     <name>SESSIONID</name>
     <value>
      <string>1234567890</string>
     </value>
    </member>
   </struct>
  </value>
 </param>
</params>
</methodCall>

Response received:

replyLine: HTTP/1.1 200 OK

HEADER : Date: Mon, 01 Mar 2004 12:09:59 GMT
HEADER : Server: Apache/1.3.27 (Linux/SuSE) mod_python/2.7.8
Python/2.2.2 PHP/4.3.5RC4-dev
HEADER : X-Powered-By: PHP/4.3.5RC4-dev
HEADER : Content-Length: 375
HEADER : Connection: close
HEADER : Content-Type: text/xml

<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
 <param>
  <value>
   <struct>
    <member>
     <name>AUTH</name>
     <value>
      <int>1</int>
     </value>
    </member>
    <member>
     <name>SESSIONID</name>
     <value>
      <string>1234567890</string>
     </value>
    </member>
   </struct>
  </value>
 </param>
</params>
</methodResponse>



Reproduce code:
---------------
<?php
function select_contact($method_name, $params, $app_data)
{
   if (count($params) == 0 || !array_key_exists("SESSIONID",
$params[0])) {
      return array("AUTH" => 0);
   } 
   
   return array("AUTH"=>1, "SESSIONID"=>$params[0]["SESSIONID"]);
} 

$xmlrpc_server = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server, "contact.select",
"select_contact");
$request_xml = $HTTP_RAW_POST_DATA;

$response = xmlrpc_server_call_method($xmlrpc_server, $request_xml,
array());
header("Content-Type: text/xml");
header("Content-Length: " . strlen($response));
print $response;
xmlrpc_server_destroy($xmlrpc_server);

?>


Expected result:
----------------
XMLRPC request sent to server:

POST /xmlrpc_server.php HTTP/1.0
Content-Type: text/xml
Content-Length: 837

<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>system.multiCall</methodName>
<params>
 <param>
  <value>
   <array>
    <data>
     <value>
      <struct>
       <member>
        <name>methodName</name>
        <value>
         <string>contact.select</string>
        </value>
       </member>
       <member>
        <name>params</name>
        <value>
         <array>
          <data>
           <value>
            <struct>
             <member>
              <name>SESSIONID</name>
              <value>
               <string>1234567890</string>
              </value>
             </member>
            </struct>
           </value>
          </data>
         </array>
        </value>
       </member>
      </struct>
     </value>
    </data>
   </array>
  </value>
 </param>
</params>
</methodCall>

I would expect response like this:

replyLine: HTTP/1.1 200 OK

HEADER : Date: Mon, 01 Mar 2004 12:09:59 GMT
HEADER : Server: Apache/1.3.27 (Linux/SuSE) mod_python/2.7.8
Python/2.2.2 PHP/4.3.5RC4-dev
HEADER : X-Powered-By: PHP/4.3.5RC4-dev
HEADER : Content-Length: 694
HEADER : Connection: close
HEADER : Content-Type: text/xml

<?xml version="1.0" encoding="iso-8859-1"?>
<methodResponse>
<params>
 <param>
  <value>
   <array>
    <data>
     <value>
      <array>
       <data>
        <value>
         <struct>
          <member>
           <name>AUTH</name>
           <value>
            <int>1</int>
           </value>
          </member>
          <member>
            <name>SESSIONID</name>
            <value>
            <string>1234567890</string>
           </value>
          </member>
         </struct>
        </value>
       </data>
      </array>
     </value>
    </data>
   </array>
  </value>
 </param>
</params>
</methodResponse>


Actual result:
--------------
XMLRPC request sent to server:

POST /xmlrpc_server.php HTTP/1.0
Content-Type: text/xml
Content-Length: 837

<?xml version="1.0" encoding="utf-8"?>
<methodCall>
<methodName>system.multiCall</methodName>
<params>
 <param>
  <value>
   <array>
    <data>
     <value>
      <struct>
       <member>
        <name>methodName</name>
        <value>
         <string>contact.select</string>
        </value>
       </member>
       <member>
        <name>params</name>
        <value>
         <array>
          <data>
           <value>
            <struct>
             <member>
              <name>SESSIONID</name>
              <value>
               <string>1234567890</string>
              </value>
             </member>
            </struct>
           </value>
          </data>
         </array>
        </value>
       </member>
      </struct>
     </value>
    </data>
   </array>
  </value>
 </param>
</params>
</methodCall>

After request is sent, HTTP connection is dropped and no response is
received.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=27446&edit=1

Reply via email to