Network-functions: add check if variables are defined
authorAlexander Marx <alexander.marx@ipfire.org>
Tue, 7 Nov 2017 13:53:27 +0000 (14:53 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 7 Nov 2017 16:19:23 +0000 (16:19 +0000)
in function network_equal and network2bin a check for undefined variables were missing.
added them.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/cfgroot/network-functions.pl

index 25f9af1..2902aab 100644 (file)
@@ -111,6 +111,10 @@ sub network_equal {
        my @bin1 = &network2bin($network1);
        my @bin2 = &network2bin($network2);
 
+       if (!defined $bin1 || !defined $bin2) {
+               return undef;
+       }
+
        if ($bin1[0] eq $bin2[0] && $bin1[1] eq $bin2[1]) {
                return 1;
        }
@@ -133,6 +137,10 @@ sub network2bin($) {
        my $address_bin = &ip2bin($address);
        my $netmask_bin = &ip2bin($netmask);
 
+       if (!defined $address_bin || !defined $netmask_bin) {
+               return undef;
+       }
+
        my $network_start = $address_bin & $netmask_bin;
 
        return ($network_start, $netmask_bin);