Skip to content

Commit

Permalink
- Fixed bug #46973 (IPv6 address filter rejects valid address)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 31, 2008
1 parent bbe70f3 commit 6328804
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ext/filter/logical_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,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;
Expand All @@ -556,20 +556,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;
Expand Down
14 changes: 14 additions & 0 deletions ext/filter/tests/bug46973.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #46973 (IPv6 address filter rejects valid address)
--FILE--
<?php

var_dump(filter_var('1fff::a88:85a3::172.31.128.1', FILTER_VALIDATE_IP,FILTER_FLAG_IPV6));
var_dump(filter_var('3ffe:6a88:85a3:08d3:1319:8a2e:0370:7344', FILTER_VALIDATE_IP,FILTER_FLAG_IPV6));
var_dump(filter_var('1fff::a88:85a3::172.31.128.1', FILTER_VALIDATE_IP,FILTER_FLAG_IPV6));

?>
--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"

0 comments on commit 6328804

Please sign in to comment.