Make WordPress Core

Opened 13 years ago

Closed 12 years ago

#1738 closed defect (bug) (duplicate)

Error in functions-post.php when $_SERVER['REMOTE_ADDR'] returns comma seperated list of IP addresses

Reported by: rgsteele Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.5.2
Component: General Keywords:
Focuses: Cc:


When certain users post comments, this error message is displayed:

Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in 
/htdocs/wp-includes/functions-post.php on line 472

The problem is on this line in functions-post.php:

$user_domain = apply_filters('pre_comment_user_domain', gethostbyaddr($user_ip) );

The problem is that $_SERVERREMOTE_ADDR? can contain a comma separated list of IP addresses, which gethostbyaddr() will choke on. The code should be changed to the following:

$ips = explode(', ', $_SERVER['REMOTE_ADDR']);
$user_domain = apply_filters('pre_comment_user_domain', gethostbyaddr($ips[0]);

This ensures that if there are multiple IPs, only the first one is used. (If there is only one IP in the list, explode returns an array with the input string, so this case will still work as well.)

Change History (2)

#1 @morydd
13 years ago

  • Keywords bg|needs-testing bg|has-patch added

#2 @Nazgul
12 years ago

  • Keywords bg|needs-testing bg|has-patch removed
  • Resolution set to duplicate
  • Status changed from new to closed

Marking a duplicate of #3197, as that one has a more recent patch.

Note: See TracTickets for help on using tickets.