Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4863 closed defect (bug) (fixed)

Bug in get_comment function from wp-includes/comment.php

Reported by: bogdanghervan's profile BogdanGhervan Owned by: westi's profile westi
Milestone: 2.3 Priority: low
Severity: normal Version:
Component: General Keywords: get_comment comment.php
Focuses: Cc:

Description

In the get_comment function, this block of code:

$comment = (int) $comment;
if ( !isset($comment_cache[$comment]) ) {
	$_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
	$comment_cache[$comment->comment_ID] = & $_comment;
}

Should change to:

$comment = (int) $comment;
if ( !isset($comment_cache[$comment]) ) {
	$_comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment' LIMIT 1");
	$comment_cache[$comment] = & $_comment;
}

$comment is an int, not an object, therefore the comment_ID property doesn't exist.

Change History (2)

#1 @westi
17 years ago

  • Owner changed from anonymous to westi
  • Status changed from new to assigned

Hmm i suspect the intention here was for it to be $_comment->comment_ID that the cache was set on.

I think we need to check that the comment actually existed before we set the cache as well.

#2 @ryan
17 years ago

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

That code was changed to use the object cache in [5666]

Note: See TracTickets for help on using tickets.