Bug #79906 [NEW]: FILTER_FLAG_NO_RES_RANGE wrong on short IPv6 addresses
From: os at tnys-welt dot de
Operating system: all
PHP version: 7.4.8
Package: Unknown/Other Function
Bug Type: Bug
Bug description:FILTER_FLAG_NO_RES_RANGE wrong on short IPv6 addresses
Description:
------------
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:
---------------
<?php
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:
----------------
bool(false)
bool(false)
Actual result:
--------------
bool(false)
string(29) "2001:db8:0:8d3:0:8a2e:70:7344"
--
Edit bug report at https://bugs.php.net/bug.php?id=79906&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79906&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79906&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79906&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79906&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79906&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79906&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79906&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79906&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79906&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79906&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79906&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79906&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79906&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79906&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79906&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79906&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79906&r=mysqlcfg
Thread (2 messages)
- os at tnys-welt dot de