Closed jordanade closed 4 years ago
Anyone know a solution? This is filling up my logs.
I have the same error :
ErrorException: Notice: Undefined offset: 1
#68 /vendor/pragmarx/support/src/IpAddress.php(232): PragmaRX\Support\IpAddress::cidrToRange
#67 /vendor/pragmarx/support/src/IpAddress.php(283): PragmaRX\Support\IpAddress::ipV4Valid
And there is no solution, you will have a notice no matter what, this needs to be fixed in the package code.
the problem is here (PragmaRX\Support\IpAddress::ipV4Valid):
try
{
// if ip is 1.2.3.4/32 then Warning: inet_pton(): Unrecognized address 1.2.3.4/32
$isIpAddress = inet_pton($ip) !== false;
}
catch(\Exception $e) {}
try
{
// if ip is 1.2.3.4 then ErrorException: Notice: Undefined offset: 1
$isRange = static::cidrToRange($ip);
}
catch(\Exception $e) {}
I had the same issue. To fix it I turned the flag 'enable_range_search' to false in the config file. It's used in the validRange method called from checkSecondaryLists method.
I'm not using cidr notation on my addresses I don't need it for now so I does work for me.
I got the same issue above even though I disabled the enable_range_search
. The $cidr exploded values only contains one value in array.
/**
* method cidrToRange.
* Returns an array of only two IPv4 addresses that have the lowest ip
* address as the first entry. If you need to check to see if an IPv4
* address is within range please use the IPisWithinCIDR method above.
* Usage:
* CIDR::cidrToRange("127.0.0.128/25");
* Result:
* array(2) {
* "127.0.0.128",
* "127.0.0.255",
* }
* @param $cidr string CIDR block
* @return Array low end of range then high end of range.
*/
public static function cidrToRange($cidr)
{
if (! preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$/", $cidr)) {
return false;
}
$range = array();
$cidr = explode('/', $cidr);
$range[0] = long2ip((ip2long($cidr[0])) & ((-1 << (32 - (int)$cidr[1]))));
$range[1] = long2ip((ip2long($cidr[0])) + pow(2, (32 - (int)$cidr[1])) - 1);
return $range;
}
I'm experiencing the same issue
What seems to fix this issue for me is to not use any wildcards.
I changed my only firewall entry from 10.*.*.*
to 10.0.0.0/8
, and I haven't gotten the warning since.
I haven't tested it enough to be sure though.
What I do know is my stacktrace shows the warning occurred in:
/vendor/pragmarx/support/src/IpAddress.php in PragmaRX\Support\IpAddress::cidrToRange at line 232
$cidr = explode('/', $cidr);
$range[0] = long2ip((ip2long($cidr[0])) & ((-1 << (32 - (int)$cidr[1]))));
We'll im not using any wildcards :'( I'm using filter by country
I created a pull request that should take care of the issue.
I have configured the 'enable_range_search' => false, and continue with this error :(
ErrorException: Notice: Undefined offset: 1
I try with ip blacklist, country blacklist and without no blacklist record and always obtain the same error.
I think that the problem is support dependency version. When firewall package is downloaded, old Support version is downloaded because 857e250 commit content is not downloaded.
It was merged, sorry for the delay.
I dont know what I'm doing wrong but, after "composer update" and with all updated, the error continues. In my code, the cidrToRange function doesn't have the if (if (count($cidr) !== 2) {) statement yet
what I do wrong?
Unfortunately I cannot reproduce your error. I have just created a new app and it works fine with 'enable_range_search' => false
I think that the problem is composer update doesnt update support package, I dont know why, and the class is inside this package.
/var/app/current/vendor/pragmarx/support/src/IpAddress.php in PragmaRX\Support\IpAddress::cidrToRange at line 232