system: let our functions deal with null == '' as they used to

There is no point in adding control flow to callers that lead
to the same result in edge cases anyway.

Some parts of the code seem to be abusing ip_in_subnet() but
we can just return false in that case as the IP is not in the
empty subnet.
This commit is contained in:
Franco Fichtner 2023-01-31 09:19:34 +01:00
parent 396fdee7cd
commit 70ced4f262

View File

@ -611,7 +611,7 @@ function is_ipaddrv4($ipaddr)
/* returns true if $ipaddr is a valid linklocal address (inside fe80::/10) */
function is_linklocal($ipaddr)
{
return preg_match('/^fe[89ab][0-9a-f]:/i', $ipaddr);
return preg_match('/^fe[89ab][0-9a-f]:/i', $ipaddr ?? '');
}
/* returns true if $ipaddr is a valid literal IPv6 address */
@ -964,7 +964,7 @@ function exec_safe($format, $args = [])
}
foreach ($args as $id => $arg) {
$args[$id] = escapeshellarg($arg);
$args[$id] = escapeshellarg($arg ?? '');
}
return vsprintf($format, $args);
@ -1051,7 +1051,9 @@ function ipcmp($a, $b)
/* return true if $addr is in $subnet, false if not */
function ip_in_subnet($addr, $subnet)
{
if (is_ipaddrv6($addr)) {
if (empty($subnet)) {
/* discard invalid input */
} elseif (is_ipaddrv6($addr)) {
return (Net_IPv6::isInNetmask($addr, $subnet));
} elseif (is_ipaddrv4($addr)) {
list($ip, $mask) = explode('/', $subnet);