WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#10659 closed defect (bug) (fixed)

wp_getPages fails if WP_DEBUG is set, and no page count parameter provided

Reported by: redsweater Owned by: westi
Milestone: 2.9 Priority: normal
Severity: normal Version: 2.8
Component: XML-RPC Keywords:
Focuses: Cc:

Description

Apparently there is a difference in the way php4 and php5 behave when it comes to missing XMLRPC parameters. In php4, the existing behavior of wp_getPages works well, causing a default page count of 10 to be used if the:

$num_pages = (int) $args[3];

line evaluates to a $num_pages that fails the test "isset()".

In PHP 5, if the client provides no 4th argument ($args[3]), then the evaluation fails abruptly with a console-written error about 3 being a bad index.

To fix this, I am providing a patch that is more deliberately defensive against a missing 4th parameter. If the 4th parameter doesn't exist, the default value of 10 pages is used. Otherwise, it is read and respected.

It might be worth evaluating other XMLRPC methods that have "optional" method arguments, to make sure they behave as expected under PHP 5.

Attachments (1)

PagesFound.diff (1.2 KB) - added by redsweater 6 years ago.

Download all attachments as: .zip

Change History (7)

@redsweater6 years ago

comment:1 @redsweater6 years ago

  • Summary changed from wp_getPages fails on PHP5 with no page count parameter to wp_getPages failsif WP_DEBUG is set, and no page count parameter provided

UPDATE: I think I was confused into thinking this is a PHP4 vs. PHP5 issue, but instead I think it's a question of whether WP_DEBUG is set to true or not.

When WP_DEBUG is true, sensitive array accesses in WordPress cause errors to be written, and thus foil the XML response.

Should these sensitive array accesses be guarded (as the patch provides for in this case), so that XMLRPC operates correctly in WP_DEBUG mode?

If so, I have another case and patch to submit.

comment:2 @redsweater6 years ago

  • Summary changed from wp_getPages failsif WP_DEBUG is set, and no page count parameter provided to wp_getPages fails if WP_DEBUG is set, and no page count parameter provided

comment:3 @westi6 years ago

  • Owner changed from josephscott to westi
  • Status changed from new to reviewing

This explains the fun I had testing #10244 this morning.

comment:4 @westi6 years ago

(In [11850]) Make the number of pages argument to wp.getPages properly optional. See #10659 props redsweater.

comment:5 @josephscott6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:6 @westi6 years ago

  • Milestone changed from Unassigned to 2.9
  • Version set to 2.8
Note: See TracTickets for help on using tickets.