]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #48762 (IPv6 address filter still rejects valid address)
authorFelipe Pena <felipe@php.net>
Thu, 16 Jul 2009 23:29:36 +0000 (23:29 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 16 Jul 2009 23:29:36 +0000 (23:29 +0000)
ext/filter/logical_filters.c
ext/filter/tests/bug48762.phpt [new file with mode: 0644]

index 555a3f914ff9c5ca4eefcd69ccb8226820333e62..bf3eaff10716e0d3b40c25a49eeacf51a8b0a96e 100644 (file)
@@ -529,7 +529,7 @@ static int _php_filter_validate_ipv6(char *str, int str_len TSRMLS_DC) /* {{{ */
        int compressed = 0;
        int blocks = 8;
        int n;
-       char *ipv4 = NULL;
+       char *ipv4;
        char *end;
        int ip4elm[4];
        char *s = str;
@@ -555,24 +555,21 @@ static int _php_filter_validate_ipv6(char *str, int str_len TSRMLS_DC) /* {{{ */
                blocks = 6;
        }
 
-       end = ipv4 ? ipv4 : str + str_len;
+       end = str + str_len;
 
        while (str < end) {
                if (*str == ':') {
                        if (--blocks == 0) {
-                               if ((str+1) == end && ipv4) {
-                                       return 1;
-                               }
                                return 0;
                        }                       
                        if (++str >= end) {
-                               return (ipv4 && ipv4 == str && blocks == 3) || 0;
+                               return 0;
                        }
                        if (*str == ':') {
                                if (compressed || --blocks == 0) {
                                        return 0;
                                }                       
-                               if (++str == end || (ipv4 && ipv4 == str)) {
+                               if (++str == end) {
                                        return 1;
                                }
                                compressed = 1;
diff --git a/ext/filter/tests/bug48762.phpt b/ext/filter/tests/bug48762.phpt
new file mode 100644 (file)
index 0000000..1737f0a
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #48762 (IPv6 address filter still rejects valid address)
+--FILE--
+<?php
+
+var_dump(filter_var('0b15:23::3:67.98.234.17', FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
+var_dump(filter_var('::67:78b:34.43.43.2', FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
+
+?>
+--EXPECT--
+string(23) "0b15:23::3:67.98.234.17"
+string(19) "::67:78b:34.43.43.2"