Skip to content

Commit 9834978

Browse files
author
Julien Pauli
committed
Fix #72972, Bad filter for the flags FILTER_FLAG_NO_RES_RANGE and FILTER_FLAG_NO_PRIV_RANGE
1 parent 5c38fbe commit 9834978

File tree

3 files changed

+31
-42
lines changed

3 files changed

+31
-42
lines changed

ext/filter/logical_filters.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,7 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
704704
if (flags & FILTER_FLAG_NO_PRIV_RANGE) {
705705
if (
706706
(ip[0] == 10) ||
707-
(ip[0] == 169 && ip[1] == 254) ||
708-
(ip[0] == 172 && (ip[1] >= 16 && ip[1] <= 31)) ||
707+
(ip[0] == 172 && ip[1] >= 16 && ip[1] <= 31) ||
709708
(ip[0] == 192 && ip[1] == 168)
710709
) {
711710
RETURN_VALIDATION_FAILED
@@ -715,19 +714,9 @@ void php_filter_validate_ip(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
715714
if (flags & FILTER_FLAG_NO_RES_RANGE) {
716715
if (
717716
(ip[0] == 0) ||
718-
(ip[0] == 10) ||
719-
(ip[0] == 100 && (ip[1] >= 64 && ip[1] <= 127)) ||
717+
(ip[0] >= 240) ||
720718
(ip[0] == 127) ||
721-
(ip[0] == 169 && ip[1] == 254) ||
722-
(ip[0] == 172 && (ip[1] >= 16 && ip[1] <= 31)) ||
723-
(ip[0] == 192 && ip[1] == 0 && ip[2] == 0) ||
724-
(ip[0] == 192 && ip[1] == 0 && ip[2] == 2) ||
725-
(ip[0] == 192 && ip[1] == 88 && ip[2] == 99) ||
726-
(ip[0] == 192 && ip[1] == 168) ||
727-
(ip[0] == 198 && (ip[1] == 18 || ip[1] == 19)) ||
728-
(ip[0] == 198 && ip[1] == 51 && ip[2] == 100) ||
729-
(ip[0] == 203 && ip[1] == 0 && ip[2] == 113) ||
730-
(ip[0] >= 224 && ip[0] <= 255)
719+
(ip[0] == 169 && ip[1] == 254)
731720
) {
732721
RETURN_VALIDATION_FAILED
733722
}

ext/filter/tests/018.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ string(9) "127.0.0.1"
4141
bool(false)
4242
string(12) "192.0.34.166"
4343
bool(false)
44-
bool(false)
45-
bool(false)
46-
bool(false)
44+
string(9) "192.0.0.1"
45+
string(10) "100.64.0.0"
46+
string(15) "100.127.255.255"
4747
string(12) "192.0.34.166"
4848
bool(false)
4949
string(15) "255.255.255.255"

ext/filter/tests/filter_ipv4_rfc6890.phpt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,53 +85,53 @@ string(10) "10.0.0.0/8"
8585
bool(false)
8686
bool(false)
8787
string(14) "168.254.0.0/16"
88-
bool(false)
89-
bool(false)
88+
string(11) "169.254.0.0"
89+
string(15) "169.254.255.255"
9090
string(13) "172.16.0.0/12"
9191
bool(false)
9292
bool(false)
9393
string(14) "192.168.0.0/16"
9494
bool(false)
9595
bool(false)
9696
string(10) "10.0.0.0/8"
97-
bool(false)
98-
bool(false)
97+
string(8) "10.0.0.0"
98+
string(14) "10.255.255.255"
9999
string(12) "10.64.0.0/10"
100-
bool(false)
101-
bool(false)
100+
string(10) "100.64.0.0"
101+
string(15) "100.127.255.255"
102102
string(11) "127.0.0.0/8"
103103
bool(false)
104104
bool(false)
105105
string(14) "169.254.0.0/16"
106106
bool(false)
107107
bool(false)
108108
string(13) "172.16.0.0/12"
109-
bool(false)
110-
bool(false)
109+
string(10) "172.16.0.0"
110+
string(10) "172.31.0.0"
111111
string(12) "192.0.0.0/24"
112-
bool(false)
113-
bool(false)
112+
string(9) "192.0.0.0"
113+
string(11) "192.0.0.255"
114114
string(12) "192.0.0.0/29"
115-
bool(false)
116-
bool(false)
115+
string(9) "192.0.0.0"
116+
string(9) "192.0.0.7"
117117
string(12) "192.0.2.0/24"
118-
bool(false)
119-
bool(false)
118+
string(9) "192.0.2.0"
119+
string(11) "192.0.2.255"
120120
string(13) "198.18.0.0/15"
121-
bool(false)
122-
bool(false)
121+
string(10) "198.18.0.0"
122+
string(14) "198.19.255.255"
123123
string(15) "198.51.100.0/24"
124-
bool(false)
125-
bool(false)
124+
string(12) "198.51.100.0"
125+
string(14) "198.51.100.255"
126126
string(14) "192.88.99.0/24"
127-
bool(false)
128-
bool(false)
127+
string(11) "192.88.99.0"
128+
string(13) "192.88.99.255"
129129
string(14) "192.168.0.0/16"
130-
bool(false)
131-
bool(false)
130+
string(11) "192.168.0.0"
131+
string(15) "192.168.255.255"
132132
string(14) "203.0.113.0/24"
133-
bool(false)
134-
bool(false)
133+
string(11) "203.0.113.0"
134+
string(13) "203.0.113.255"
135135
string(11) "240.0.0.0/4"
136-
bool(false)
136+
string(9) "224.0.0.0"
137137
bool(false)

0 commit comments

Comments
 (0)