Ticket #1738 (closed defect (bug): duplicate)

Opened 7 years ago

Last modified 6 years ago

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

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

Description

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

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

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

Note: See TracTickets for help on using tickets.