Bug #67311 [NEW]: FILTER_VALIDATE_IP bug with array reference
| From: | bug_34 at hotmaill dot com | Date: | Tue, 20 May 2014 14:01:52 +0000 |
| Subject: | Bug #67311 [NEW]: FILTER_VALIDATE_IP bug with array reference | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185875@lists.php.net to get a copy of this message | ||
From: bug_34 at hotmaill dot com
Operating system: Windows XP
PHP version: Irrelevant
Package: Filter related
Bug Type: Bug
Bug description:FILTER_VALIDATE_IP bug with array reference
Description:
------------
FILTER_VALIDATE_IP is not working as expected. Please see code snippet.
PHP version: 5.4.16
OS: Windows XP
Works:
if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' =>
array(FILTER_FLAG_IPV4, FILTER_FLAG_NO_PRIV_RANGE,
FILTER_FLAG_NO_RES_RANGE))) !== false) {
Does not work:
if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' =>
array(FILTER_FLAG_IPV6, FILTER_FLAG_NO_PRIV_RANGE))) !== false) {
Works:
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 |
FILTER_FLAG_NO_PRIV_RANGE) !== false) {
I didn't test it on different OS and PHP versions.
Test script:
---------------
<?php
function is_ip($ip, $version = null) {
switch ($version) {
case 4:
if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' =>
array(FILTER_FLAG_IPV4, FILTER_FLAG_NO_PRIV_RANGE,
FILTER_FLAG_NO_RES_RANGE))) !== false) {
return "passed <br />\n";
}
break;
case 6:
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false)
{
return "passed <br />\n";
}
break;
case 'bug':
if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' =>
array(FILTER_FLAG_IPV6, FILTER_FLAG_NO_PRIV_RANGE))) !== false) {
return "passed <br />\n";
}
default:
if (filter_var($ip, FILTER_VALIDATE_IP, array('flags' =>
array(FILTER_FLAG_IPV4, FILTER_FLAG_IPV6, FILTER_FLAG_NO_PRIV_RANGE,
FILTER_FLAG_NO_RES_RANGE))) !== false) {
return "passed <br />\n";
}
break;
}
return "didn't pass <br />\n";
}
$ip = "127.0.0.1";
echo "IP address validation test: " . $ip . "<br />\n";
echo "v4: ". is_ip($ip, 4);
echo "v6: ". is_ip($ip, 6);
echo "v6: ". is_ip($ip, 'bug');
echo "v4 or v6: ". is_ip($ip);
Expected result:
----------------
The expected result:
IP address validation test: 127.0.0.1
v4: passed
v6: didn't pass
v6: didn't pass
v4 or v6: passed
Actual result:
--------------
The actual result:
IP address validation test: 127.0.0.1
v4: passed
v6: didn't pass
v6: passed
v4 or v6: passed
--
Edit bug report at https://bugs.php.net/bug.php?id=67311&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67311&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67311&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67311&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67311&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67311&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67311&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67311&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67311&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67311&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67311&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67311&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67311&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67311&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67311&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67311&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67311&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67311&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67311&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67311&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67311&r=mysqlcfg