Fixed bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges)

This commit is contained in:
Ilia Alshanetsky 2010-12-12 18:36:21 +00:00
parent 071513562d
commit c1e9f628a0
4 changed files with 39 additions and 1 deletions

4
NEWS
View File

@ -6,6 +6,10 @@
- Zend Engine: - Zend Engine:
. Indirect reference to $this fails to resolve if direct $this is never used . Indirect reference to $this fails to resolve if direct $this is never used
in method. (Scott) in method. (Scott)
- Filter extension:
. Fixed bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges).
(Ilia)
- Intl extension: - Intl extension:
. Fixed bug #53512 (NumberFormatter::setSymbol crash on bogus $attr values). . Fixed bug #53512 (NumberFormatter::setSymbol crash on bogus $attr values).

View File

@ -710,8 +710,11 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
if (flags & FILTER_FLAG_NO_RES_RANGE) { if (flags & FILTER_FLAG_NO_RES_RANGE) {
if ( if (
(ip[0] == 0) || (ip[0] == 0) ||
(ip[0] == 128 && ip[1] == 0) ||
(ip[0] == 191 && ip[1] == 255) ||
(ip[0] == 169 && ip[1] == 254) || (ip[0] == 169 && ip[1] == 254) ||
(ip[0] == 192 && ip[1] == 0 && ip[2] == 2) || (ip[0] == 192 && ip[1] == 0 && ip[2] == 2) ||
(ip[0] == 127 && ip[1] == 0 && ip[2] == 0 && ip[3] == 1) ||
(ip[0] >= 224 && ip[0] <= 255) (ip[0] >= 224 && ip[0] <= 255)
) { ) {
RETURN_VALIDATION_FAILED RETURN_VALIDATION_FAILED
@ -732,6 +735,9 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
RETURN_VALIDATION_FAILED RETURN_VALIDATION_FAILED
} }
} }
if (flags & FILTER_FLAG_NO_RES_RANGE && Z_STRLEN_P(value) == 3 && !strcmp("::1", Z_STRVAL_P(value))) {
RETURN_VALIDATION_FAILED
}
} }
break; break;
} }

View File

@ -37,7 +37,7 @@ bool(false)
string(9) "127.0.0.1" string(9) "127.0.0.1"
bool(false) bool(false)
string(12) "192.0.34.166" string(12) "192.0.34.166"
string(9) "127.0.0.1" bool(false)
string(9) "192.0.0.1" string(9) "192.0.0.1"
string(12) "192.0.34.166" string(12) "192.0.34.166"
bool(false) bool(false)

View File

@ -0,0 +1,28 @@
--TEST--
Bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges)
--SKIPIF--
<?php if (!extension_loaded("filter")) die("skip"); ?>
--FILE--
<?php
var_dump(filter_var('127.0.0.1', FILTER_VALIDATE_IP));
var_dump(filter_var("::1", FILTER_VALIDATE_IP));
var_dump(filter_var('127.0.0.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
var_dump(filter_var('::1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
var_dump(filter_var('128.0.0.1', FILTER_VALIDATE_IP));
var_dump(filter_var('128.0.0.1', FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
var_dump(filter_var('191.255.0.0', FILTER_VALIDATE_IP));
var_dump(filter_var('191.255.0.0', FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
?>
--EXPECT--
string(9) "127.0.0.1"
string(3) "::1"
bool(false)
bool(false)
string(9) "128.0.0.1"
bool(false)
string(11) "191.255.0.0"
bool(false)