From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer To: development@lists.ipfire.org Subject: Re: [PATCH] Network-functions: add check if variables are defined Date: Tue, 07 Nov 2017 16:20:20 +0000 Message-ID: <1510071620.4838.313.camel@ipfire.org> In-Reply-To: <1510062807-12906-1-git-send-email-alexander.marx@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4916207476281068226==" List-Id: --===============4916207476281068226== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi, this patch conflicted with the previous one that you sent today. It would have been better to send them all together in one patchset. It also had some whitespace errors. However, I edited this and merged it. -Michael On Tue, 2017-11-07 at 14:53 +0100, Alexander Marx wrote: > in function network_equal and network2bin a check for undefined variables w= ere > missing. > added them. > --- > config/cfgroot/network-functions.pl | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) >=20 > diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network- > functions.pl > index 93b8190..9e50d7c 100644 > --- a/config/cfgroot/network-functions.pl > +++ b/config/cfgroot/network-functions.pl > @@ -108,10 +108,14 @@ sub network_equal { > my $network1 =3D shift; > my $network2 =3D shift; > =20 > - my $bin1 =3D &network2bin($network1); > - my $bin2 =3D &network2bin($network2); > + my @bin1 =3D &network2bin($network1); > + my @bin2 =3D &network2bin($network2); > =20 > - if ($bin1 eq $bin2) { > + if(!defined $bin1 || !defined $bin2){ > + return undef; > + } > + > + if ($bin1[0] eq $bin2[0] && $bin1[1] eq $bin2[1]){ > return 1; > } > =20 > @@ -132,6 +136,10 @@ sub network2bin($) { > =20 > my $address_bin =3D &ip2bin($address); > my $netmask_bin =3D &ip2bin($netmask); > +=09 > + if (!defined $address_bin || !defined $netmask_bin){ > + return undef; > + } > =20 > my $network_start =3D $address_bin & $netmask_bin; > =20 > @@ -457,7 +465,7 @@ sub testsuite() { > assert(!$result); > =20 > $result =3D &network_equal("192.168.0.1/24", "192.168.0.XXX/24"); > - assert($result); > + assert(!$result); > =20 > $result =3D &ip_address_in_network("10.0.1.4", "10.0.0.0/8"); > assert($result); --===============4916207476281068226== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KCmlRSXpCQUFCQ2dBZEZpRUU1L3JXNWwzR0dl Mnlwa3R4Z0hudy8yK1FDUWNGQWxvQjNVUUFDZ2tRZ0hudy8yK1EKQ1FjQlNoQUFxMkJIOEdITnFq eDQ4cGltbzVVMThKVHdYaDhJcDZQUTg3Y1VrMUEwYWNGQzVhbHVQQUhTL2VZQwp4MThNbHRKREVR c3FHdEtQYUxKVldzeTFPT3FHR2Y3cGdFS1BqckdpU0JTQVd1RDc0UHc4ckZBNWVubnUwTlFRCnNE S0s1ZlVxQmtSM29zZ1hJcWtYU1kzYzBPU1U2TWRqSkJ3cm5ENzJkV281L0FobjMvN3dOeFpOUUxF eFJrNCsKeU1Xa0J3b25mWjZ5L2F3R0FYSkUxUCtwV2s3NkZSdGl5QUJpcXoxcG9ZN080ejQyMDJ0 WkJZY0JpUmxsM3F2Kwp6WjJaUHJKUTh4MlJ1SWkySGl3cEU4cnpqVUNoUEhhNmRSdzdFc2RkZlJ4 dTdIbS9XcEl2QUw3OXNUYlJveEpGCjNVNnJldlE2MW9SeDE1OTJwbGcyS2FrSFZOZWp0aUR6dzZa SEVJWmxoVWZtQzZpRnc2d1FnTCszcUM5YThLU3kKWmNreG5SelZHVXFLRFFKVzI2c2RFRTRSc1hI RjJGL05EY3krL3FqYUJkTFdBQXdPZGFnTXhhTXlqa1RBYXhlYQpwQ05SRWNBQ0xTSTY3VEFCdGpF TkcxOEtpcGRsSnZQNm5TOWRuTUNETVcwclVvZk1LMXI2dXFzY3dlTnNFM0xkCm5VajhjSmFMWDNr NlJkS3NNdzlHcVdiMU9kcnFLRW9Vb3B4NDlxTGhJV2xjZzlHUm9WellIVVBEay9aSnpoeEIKcTBF djNMekV5MTBPVHJSRGF5cWRXRTZQa3V3Zmc1V3F1dzA5WG9YK2p6MERhajhDWmx2cHMyaUx3M3hR N0M4ZAp0S0xtNlZWQjZsVmZMR2kxQTJ4Wml4SjB3TFJMOU9KZWdRbkZ1Vnh6SnF5YXpWRVMvYVk9 Cj02VnErCi0tLS0tRU5EIFBHUCBTSUdOQVRVUkUtLS0tLQo= --===============4916207476281068226==--