From c6bbf9ee57c39ade0563abd2e44ccd7d6f35fca0 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sun, 12 Dec 2010 18:36:21 +0000 Subject: [PATCH] Fixed bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges) --- ext/filter/logical_filters.c | 6 ++++++ ext/filter/tests/018.phpt | 2 +- ext/filter/tests/bug53150.phpt | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ext/filter/tests/bug53150.phpt diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index 6bf83b9cef2..f6a7c82fd28 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -710,8 +710,11 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ if (flags & FILTER_FLAG_NO_RES_RANGE) { if ( (ip[0] == 0) || + (ip[0] == 128 && ip[1] == 0) || + (ip[0] == 191 && ip[1] == 255) || (ip[0] == 169 && ip[1] == 254) || (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) ) { RETURN_VALIDATION_FAILED @@ -732,6 +735,9 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ 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; } diff --git a/ext/filter/tests/018.phpt b/ext/filter/tests/018.phpt index 10840aae74e..13122bdc557 100644 --- a/ext/filter/tests/018.phpt +++ b/ext/filter/tests/018.phpt @@ -37,7 +37,7 @@ bool(false) string(9) "127.0.0.1" bool(false) string(12) "192.0.34.166" -string(9) "127.0.0.1" +bool(false) string(9) "192.0.0.1" string(12) "192.0.34.166" bool(false) diff --git a/ext/filter/tests/bug53150.phpt b/ext/filter/tests/bug53150.phpt new file mode 100644 index 00000000000..4baa4db772a --- /dev/null +++ b/ext/filter/tests/bug53150.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #53150 (FILTER_FLAG_NO_RES_RANGE is missing some IP ranges) +--SKIPIF-- + +--FILE-- + +--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)