Skip to content

Commit 8849a53

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. Closes GH-18312.
1 parent ba08538 commit 8849a53

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PHP NEWS
66
. Fixed bug GH-18304 (Changing the properties of a DateInterval through
77
dynamic properties triggers a SegFault). (nielsdos)
88

9+
- Filter:
10+
. Fixed bug GH-18309 (ipv6 filter integer overflow). (nielsdos)
11+
912
- GD:
1013
. Fixed imagecrop() overflow with rect argument with x/width y/heigh usage
1114
in gdImageCrop(). (David Carlier)

ext/filter/logical_filters.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ 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;
766+
int i;
766767
char *ipv4;
767768
const char *end;
768769
int ip4elm[4];

ext/filter/tests/gh18309.phpt

+10
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)