Skip to content

Commit f9a16d4

Browse files
committed
Fix GH-18309: ipv6 filter integer overflow
The intermediate computation can cause a signed integer overflow, but the input is correctly rejected later on by the check on variable `n`. Solve this by using an unsigned number.
1 parent 90f582b commit f9a16d4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ext/filter/logical_filters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ static int _php_filter_validate_ipv6(const char *str, size_t str_len, int ip[8])
762762
{
763763
int compressed_pos = -1;
764764
int blocks = 0;
765-
int num, n, i;
765+
unsigned int num, n, i;
766766
char *ipv4;
767767
const char *end;
768768
int ip4elm[4];

ext/filter/tests/gh18309.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
GH-18309 (ipv6 filter integer overflow)
3+
--EXTENSIONS--
4+
filter
5+
--FILE--
6+
<?php
7+
var_dump(filter_var('fffffffffffffffffffffffffffffffffffff::', FILTER_VALIDATE_IP, FILTER_FLAG_IPV6));
8+
?>
9+
--EXPECT--
10+
bool(false)

0 commit comments

Comments
 (0)