WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/17/2018 06:38:13 PM (3 years ago)
Author:
desrosj
Message:

WPDB: Check that $wpdb->last_result is countable before counting with it.

wpdb::get_col() iterates over $wpdb->last_result, which can be a non-countable value, should the preceding query have failed.

Props spacedmonkey, desrosj, pento.

Merges [43934] into trunk.

See #45299.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/wp-db.php

    r43571 r44272  
    25452545        $new_array = array();
    25462546        // Extract the column values
    2547         for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
    2548             $new_array[ $i ] = $this->get_var( null, $x, $i );
     2547        if ( $this->last_result ) {
     2548            for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
     2549                $new_array[ $i ] = $this->get_var( null, $x, $i );
     2550            }
    25492551        }
    25502552        return $new_array;
     
    25862588            // Return an array of row objects with keys from column 1
    25872589            // (Duplicates are discarded)
    2588             foreach ( $this->last_result as $row ) {
    2589                 $var_by_ref = get_object_vars( $row );
    2590                 $key        = array_shift( $var_by_ref );
    2591                 if ( ! isset( $new_array[ $key ] ) ) {
    2592                     $new_array[ $key ] = $row;
     2590            if ( $this->last_result ) {
     2591                foreach ( $this->last_result as $row ) {
     2592                    $var_by_ref = get_object_vars( $row );
     2593                    $key        = array_shift( $var_by_ref );
     2594                    if ( ! isset( $new_array[ $key ] ) ) {
     2595                        $new_array[ $key ] = $row;
     2596                    }
    25932597                }
    25942598            }
Note: See TracChangeset for help on using the changeset viewer.