Make WordPress Core

Opened 16 years ago

Closed 16 years ago

#7953 closed defect (bug) (fixed)

get_post_meta return incorrect data under certain circumstances

Reported by: markedwards's profile markedwards Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch, needs-testing
Focuses: Cc:

Description

If a post has a record in the postmeta table with a blank/empty meta_key name and get_post_meta is called using a blank meta_key or one that does not exist then get_post_meta might return the meta_value for a previously existing table record that has a blank meta_key name.

Example where this might happen: Developer A writes a plugin that mistakenly inserts post meta data without a key name (e.g. meta_key is blank). Developer B writes a plugin that mistakenly tries to get post meta data using a meta_key name that does not exist (whether accidentally, or intentionally to determine if a key exists). Under those circumstances Developer B's call to get_post_meta will return the meta_value having a blank meta_key name, as previously written to the database by Developer A.

To test this scenario inject a record for a given post ID into the table without a meta_key name (e.g. empty meta_key name) but WITH a meta value. Then called get_post_meta on the associated post ID using any meta_key name known not to be associated with the post ID. The return result will be the value associated with the record having the empty meta_key name.

The solution is to make sure that the functions get_post_meta, add_post_meta, delete_post_meta, and update_post_meta (in wp-includes/post.php) all check for a blank key name before taking any action and if the key is blank return accordingly per the function: return false for add_post_meta, delete_post_meta, and update_post_meta; and return empty for get_post_meta).

Attachments (1)

7953.diff (2.1 KB) - added by Denis-de-Bernardy 16 years ago.

Download all attachments as: .zip

Change History (4)

#1 @markedwards
16 years ago

Sorry, forgot to mention - this is the case on WP 2.6.2 and most likely previous versions.

#2 @Denis-de-Bernardy
16 years ago

  • Keywords has-patch needs-testing added; post meta get_post_meta removed

#3 @automattor
16 years ago

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

(In [10711]) Check for empty meta keys. Props Denis-de-Bernardy, markedwards. fixes #7953

Note: See TracTickets for help on using tickets.