|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79906 FILTER_FLAG_NO_RES_RANGE wrong on short IPv6 addresses
Submitted: 2020-07-28 12:05 UTC Modified: -
From: os at tnys-welt dot de Assigned:
Status: Open Package: Unknown/Other Function
PHP Version: 7.4.8 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
35 - 16 = ?
Subscribe to this entry?

 [2020-07-28 12:05 UTC] os at tnys-welt dot de
The flag FILTER_FLAG_NO_RES_RANGE for IPv6 is working internally with strncasecmp and does not take into account, that IPv6 addresses may be shortened by removing leading zeros.

line 900ff of ext/filter/logical_filters.c:
(Z_STRLEN_P(value) >= 9 &&  !strncasecmp("2001:0db8", Z_STRVAL_P(value), 9)) ||
(Z_STRLEN_P(value) >= 2 &&  !strncasecmp("5f", Z_STRVAL_P(value), 2)) ||
(Z_STRLEN_P(value) >= 4 &&  !strncasecmp("3ff3", Z_STRVAL_P(value), 4)) ||
(Z_STRLEN_P(value) >= 8 &&  !strncasecmp("2001:001", Z_STRVAL_P(value), 8))

Test script:

var_dump(filter_var('2001:0db8:0000:08d3:0000:8a2e:0070:7344', FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));
var_dump(filter_var('2001:db8:0:8d3:0:8a2e:70:7344', FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE));

Expected result:

Actual result:
string(29) "2001:db8:0:8d3:0:8a2e:70:7344"


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Mar 05 20:01:24 2021 UTC