Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#5226 closed defect (bug) (fixed)

Potential fatal object type mismatch in wp_set_object_terms()

Reported by: tellyworth's profile tellyworth Owned by:
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3
Component: General Keywords: has-patch
Focuses: Cc:

Description

The wp_set_object_terms() function calls wp_insert_term() and then immediately assumes the return result is an array, around line 1121:

		if ( !$id = is_term($term, $taxonomy) )
			$id = wp_insert_term($term, $taxonomy);
		$term_ids[] = $id['term_id'];

But wp_insert_term() doesn't always return an array, it can return a WP_Error object. This causes a fatal error:

PHP Fatal error: Cannot use object of type WP_Error as array in wordpress/wp-includes/taxonomy.php on line 1122

This turned up while I was writing unit tests. I'm not quite sure what the cause is yet because I can't backtrace a fatal error. It might not happen in normal operation, but I don't think a blind assumption like that is safe considering the consequences.

Attachments (1)

taxonomy-error-check-r6270.patch (488 bytes) - added by tellyworth 17 years ago.

Download all attachments as: .zip

Change History (5)

#1 @Viper007Bond
17 years ago

  • Keywords needs-patch added
  • Milestone changed from 2.5 to 2.4
  • Version set to 2.3

#2 @tellyworth
17 years ago

Found the trigger - my fault, a filter gone bad that was causing a NULL category name. Nevertheless, I think the code still needs an error check.

#3 @tellyworth
17 years ago

  • Keywords has-patch added; needs-patch removed

The above patch fixes it. I reproduced the same trigger and confirmed that there's no fatal error with the patch applied.

#4 @ryan
17 years ago

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

(In [6271]) Catch WP_Error. Props tellyworth. fixes #5226

Note: See TracTickets for help on using tickets.