From 588a72d358d7034129acf54aea50c279eccaacc0 Mon Sep 17 00:00:00 2001 From: ligc Date: Mon, 12 Nov 2012 14:48:48 +0000 Subject: [PATCH] fix for bug 3168: safeguard code in NetworkUtils::ishostinsubnet, for 127.0.0.1 subnet git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@14308 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/NetworkUtils.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm index 5494f0da8..339b6add4 100755 --- a/perl-xCAT/xCAT/NetworkUtils.pm +++ b/perl-xCAT/xCAT/NetworkUtils.pm @@ -412,12 +412,18 @@ sub linklocaladdr { #------------------------------------------------------------------------------- sub ishostinsubnet { my ($class, $ip, $mask, $subnet) = @_; + + #safe guard + if (!defined($ip) || !defined($mask) || !defined($subnet)) + { + return 0; + } my $numbits=32; if ($ip =~ /:/) {#ipv6 $numbits=128; } # IPv6 subnet with netmask postfix like /64 - if ($subnet =~ /\//) + if ($subnet && ($subnet =~ /\//)) { $subnet =~ s/\/.*$//; } @@ -429,7 +435,7 @@ sub ishostinsubnet { $mask=getipaddr($mask,GetNumber=>1); } } else { #CIDR notation supported - if ($subnet =~ /\//) { + if ($subnet && ($subnet =~ /\//)) { ($subnet,$mask) = split /\//,$subnet,2; $mask=Math::BigInt->new("0b".("1"x$mask).("0"x($numbits-$mask))); } else {