Ticket #5226 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Potential fatal object type mismatch in wp_set_object_terms()

Reported by: tellyworth Assigned to: anonymous
Priority: normal Milestone: 2.5
Component: General Version: 2.3
Severity: normal Keywords: has-patch
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

taxonomy-error-check-r6270.patch (488 bytes) - added by tellyworth on 10/18/07 12:14:35.

Change History

10/18/07 08:10:39 changed by Viper007Bond

  • keywords set to needs-patch.
  • version set to 2.3.
  • milestone changed from 2.5 to 2.4.

10/18/07 10:44:19 changed by tellyworth

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.

10/18/07 12:14:35 changed by tellyworth

  • attachment taxonomy-error-check-r6270.patch added.

10/18/07 12:15:44 changed by tellyworth

  • keywords changed from needs-patch to has-patch.

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

10/18/07 15:55:16 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

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