From 154d823ad0035b9367bebbd95e51ba6b4ff63e87 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 31 Dec 2008 15:39:48 +0000 Subject: [PATCH] - MFH: Fixed bug #46973 (IPv6 address filter rejects valid address) --- ext/filter/logical_filters.c | 14 +++++++++----- ext/filter/tests/bug46973.phpt | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 ext/filter/tests/bug46973.phpt diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c index 05a8eaf7d3..4e64aabfef 100644 --- a/ext/filter/logical_filters.c +++ b/ext/filter/logical_filters.c @@ -526,7 +526,7 @@ static int _php_filter_validate_ipv6(char *str, int str_len TSRMLS_DC) /* {{{ */ int compressed = 0; int blocks = 8; int n; - char *ipv4; + char *ipv4 = NULL; char *end; int ip4elm[4]; char *s = str; @@ -552,20 +552,24 @@ static int _php_filter_validate_ipv6(char *str, int str_len TSRMLS_DC) /* {{{ */ blocks = 6; } - end = str + str_len; + end = ipv4 ? ipv4 : str + str_len; + while (str < end) { if (*str == ':') { if (--blocks == 0) { + if ((str+1) == end && ipv4) { + return 1; + } return 0; } if (++str >= end) { - return 0; + return (ipv4 && ipv4 == str && blocks == 3) || 0; } if (*str == ':') { if (compressed || --blocks == 0) { - return 0; + return ipv4 != NULL; } - if (++str == end) { + if (++str == end || (ipv4 && ipv4 == str)) { return 1; } compressed = 1; diff --git a/ext/filter/tests/bug46973.phpt b/ext/filter/tests/bug46973.phpt new file mode 100644 index 0000000000..c9c5ba4301 --- /dev/null +++ b/ext/filter/tests/bug46973.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #46973 (IPv6 address filter rejects valid address) +--FILE-- + +--EXPECTF-- +string(28) "1fff::a88:85a3::172.31.128.1" +string(39) "3ffe:6a88:85a3:08d3:1319:8a2e:0370:7344" +string(28) "1fff::a88:85a3::172.31.128.1" -- 2.40.0