Skip to content

Commit

Permalink
use maybe_unserialize() in update and API checks, Tighten up the chec…
Browse files Browse the repository at this point in the history
…ks on expected return data to avoid processing invalid responses after change. See #19617

git-svn-id: http://svn.automattic.com/wordpress/trunk@19707 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
dd32 committed Jan 8, 2012
1 parent 01736fb commit 3686bc4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions wp-admin/includes/plugin-install.php
Expand Up @@ -45,9 +45,9 @@ function plugins_api($action, $args = null) {
if ( is_wp_error($request) ) {
$res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
} else {
$res = unserialize( wp_remote_retrieve_body( $request ) );
if ( false === $res )
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
if ( ! is_object( $res ) && ! is_array( $res ) )
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred during the API request.'), wp_remote_retrieve_body( $request ) );
}
} elseif ( !is_wp_error($res) ) {
$res->external = true;
Expand Down
8 changes: 4 additions & 4 deletions wp-admin/includes/theme.php
Expand Up @@ -409,12 +409,12 @@ function themes_api($action, $args = null) {
if ( is_wp_error($request) ) {
$res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
} else {
$res = unserialize( wp_remote_retrieve_body( $request ) );
if ( ! $res )
$res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
$res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
if ( ! is_object( $res ) && ! is_array( $res ) )
$res = new WP_Error('themes_api_failed', __('An unknown error occurred during the API request.'), wp_remote_retrieve_body( $request ) );
}
}
//var_dump(array($args, $res));

return apply_filters('themes_api_result', $res, $action, $args);
}

Expand Down
15 changes: 8 additions & 7 deletions wp-includes/update.php
Expand Up @@ -91,10 +91,11 @@ function wp_version_check() {
return false;

$body = trim( wp_remote_retrieve_body( $response ) );
if ( ! $body = maybe_unserialize( $body ) )
return false;
if ( ! isset( $body['offers'] ) )
$body = maybe_unserialize( $body );

if ( ! is_array( $body ) || ! isset( $body['offers'] ) )
return false;

$offers = $body['offers'];

foreach ( $offers as &$offer ) {
Expand Down Expand Up @@ -205,9 +206,9 @@ function wp_update_plugins() {
if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
return false;

$response = unserialize( wp_remote_retrieve_body( $raw_response ) );
$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );

if ( false !== $response )
if ( is_array( $response ) )
$new_option->response = $response;
else
$new_option->response = array();
Expand Down Expand Up @@ -319,8 +320,8 @@ function wp_update_themes() {
$new_update->last_checked = time( );
$new_update->checked = $checked;

$response = unserialize( wp_remote_retrieve_body( $raw_response ) );
if ( false !== $response )
$response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
if ( is_array( $response ) )
$new_update->response = $response;

set_site_transient( 'update_themes', $new_update );
Expand Down

0 comments on commit 3686bc4

Please sign in to comment.