WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#27424 new defect (bug)

Dubious code flow in add_metadata()

Reported by: Denis-de-Bernardy Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.8.1
Component: Options, Meta APIs Keywords: close needs-patch
Focuses: Cc:

Description

The code goes:

	$result = $wpdb->insert( $table, array(
		$column => $object_id,
		'meta_key' => $meta_key,
		'meta_value' => $meta_value
	) );

	if ( ! $result )
		return false;

	$mid = (int) $wpdb->insert_id;

	wp_cache_delete($object_id, $meta_type . '_meta');

If $result up there is false, it probably means the key exists in the database. In other words, the cache is stale.

Should be:

	$result = $wpdb->insert( $table, array(
		$column => $object_id,
		'meta_key' => $meta_key,
		'meta_value' => $meta_value
	) );

	wp_cache_delete($object_id, $meta_type . '_meta');

	if ( ! $result )
		return false;

	$mid = (int) $wpdb->insert_id;

Change History (2)

#1 @nacin
4 years ago

I'm not sure. add_metadata() doesn't do any cache fetching or setting operations. The issue would be that a race between two add_metadata() calls would cause the second one to fail. At that point, the DB and cache should still be the same.

#2 @chriscct7
2 years ago

  • Keywords close needs-patch added
Note: See TracTickets for help on using tickets.