php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49496 xmlrpc_is_fault() should not throw a Notice when given argument is not an array
Submitted: 2009-09-08 07:18 UTC Modified: 2010-12-29 12:22 UTC
From: torben@php.net Assigned:
Status: Open Package: XMLRPC-EPI related
PHP Version: 5.3SVN-2009-09-08 (SVN) OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-09-08 07:18 UTC] torben@php.net
Description:
------------
In bug #40793 and doc bug #49378 it is reported that xmlrpc_is_fault() throws a Notice when the passed argument is not an array. In the comments for #40793 tony2001@php.net states that this is by design, and indeed it appears to be, but that would seem to be a broken design. xmlrpc_is_fault() should simply return true if the passed argument represents an xmlrpc fault, and false otherwise.

Patch for PHP 5.2:

Index: ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- ext/xmlrpc/xmlrpc-epi-php.c	(revision 287478)
+++ ext/xmlrpc/xmlrpc-epi-php.c	(working copy)
@@ -1445,7 +1445,7 @@
 /* }}} */
 
 /* {{{ proto bool xmlrpc_is_fault(array)
-   Determines if an array value represents an XMLRPC fault. */
+   Determines if the passed value represents an XMLRPC fault. */
 PHP_FUNCTION(xmlrpc_is_fault)
 {
 	zval **arg, **val;
@@ -1455,20 +1455,20 @@
 	}
 
 	if (Z_TYPE_PP(arg) != IS_ARRAY) {
-		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array argument expected");
-	} else {
-		/* The "correct" way to do this would be to call the xmlrpc
-		 * library XMLRPC_ValueIsFault() func.  However, doing that
-		 * would require us to create an xmlrpc value from the php
-		 * array, which is rather expensive, especially if it was
-		 * a big array.  Thus, we resort to this not so clever hackery.
-		 */
-		if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS && 
-		    zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS) {
-			RETURN_TRUE;
-		}
+		RETURN_FALSE;
 	}
 
+	/* The "correct" way to do this would be to call the xmlrpc
+	 * library XMLRPC_ValueIsFault() func.  However, doing that
+	 * would require us to create an xmlrpc value from the php
+	 * array, which is rather expensive, especially if it was
+	 * a big array.  Thus, we resort to this not so clever hackery.
+	 */
+	if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS && 
+	    zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS) {
+		RETURN_TRUE;
+	}
+
 	RETURN_FALSE;
 }
 /* }}} */


Patch for PHP 5.3:

Index: ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- ext/xmlrpc/xmlrpc-epi-php.c	(revision 287473)
+++ ext/xmlrpc/xmlrpc-epi-php.c	(working copy)
@@ -1495,20 +1495,24 @@
    Determines if an array value represents an XMLRPC fault. */
 PHP_FUNCTION(xmlrpc_is_fault)
 {
-	zval *arg, **val;
+	zval **arg, **val;
 
-	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arg) == FAILURE) {
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
 		return;
 	}
 
+	if (Z_TYPE_PP(arg) != IS_ARRAY) {
+		RETURN_FALSE;
+	}
+
 	/* The "correct" way to do this would be to call the xmlrpc
 	 * library XMLRPC_ValueIsFault() func.  However, doing that
 	 * would require us to create an xmlrpc value from the php
 	 * array, which is rather expensive, especially if it was
 	 * a big array.  Thus, we resort to this not so clever hackery.
 	 */
-	if (zend_hash_find(Z_ARRVAL_P(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS && 
-		zend_hash_find(Z_ARRVAL_P(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS) {
+	if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN + 1, (void**) &val) == SUCCESS && 
+		zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, FAULT_STRING_LEN + 1, (void**) &val) == SUCCESS) {
 		RETURN_TRUE;
 	}
 



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-29 12:22 UTC] jani@php.net
-Package: Feature/Change Request +Package: XMLRPC-EPI related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 06:01:26 2019 UTC