Ticket #1738 (closed defect: duplicate)

Opened 3 years ago

Last modified 2 years ago

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

Reported by: rgsteele Assigned to: 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

11/07/05 14:31:27 changed by morydd

  • keywords set to bg|needs-testing bg|has-patch.

10/04/06 00:26:31 changed by Nazgul

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to duplicate.

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