added checks for improper colons and newlines in the client xml. XCATXMLWARNING is the env variable to set to enable it

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@7098 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
cjhardee 2010-08-16 15:13:39 +00:00
parent cd97708182
commit 9db0c3a358

View File

@ -157,6 +157,9 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog
}
my $msg=XMLout($request,RootName=>'xcatrequest',NoAttr=>1,KeyAttr=>[]);
if ($ENV{XCATXMLTRACE}) { print $msg; }
if($ENV{XCATXMLWARNING}) {
validateXML($msg);
}
$SIG{TERM} = $SIG{INT} = sub { print $client XMLout({abortcommand=>1},RootName=>'xcatrequest',NoAttr=>1,KeyAttr=>[]); exit 0; };
print $client $msg;
my $response;
@ -168,8 +171,11 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog
#replace ESC with xxxxESCxxx because XMLin cannot handle it
$response =~ s/\e/xxxxESCxxxx/g;
if ($ENV{XCATXMLTRACE}) { print $response; }
if ($ENV{XCATXMLTRACE}) { print $response; }
$rsp = XMLin($response,SuppressEmpty=>undef,ForceArray=>1);
if($ENV{XCATXMLWARNING}) {
validateXML($response);
}
#add ESC back
foreach my $key (keys %$rsp) {
@ -196,6 +202,35 @@ $request->{clienttype}->[0] = "cli"; # setup clienttype for auditlog
print STDERR "ERROR/WARNING: communication with the xCAT server seems to have been ended prematurely\n";
}
sub validateXML {
my $xml = shift;
my @lines = split /\n/, $xml;
my $invalidNewline = 0;
my $contentsColon = 0;
my $contentsLine;
foreach (@lines) {
if(!$invalidNewline) {
if( ($_ =~ /<contents>/ && $_ !~ /<\/contents>/) ||
($_ =~ /<desc>/ && $_ !~ /<\/desc>/)) {
$invalidNewline = 1;
print "Possible invalid XML using newlines found: \n$xml\n";
}
}
if($_ =~ /<contents>.+:.+<\/contents>/) {
$contentsColon = 1;
$contentsLine = $_;
}
if($_ =~ /<desc>.+<\/desc>/) {
$contentsColon = 0;
}
if($contentsColon && $_ =~ /<desc><\/desc>/) {
print "Possible invalid XML found(data contents using colon and blank description): \n$contentsLine\n$_\n";
$contentsColon = 0;
}
}
}
###################################
# scan_plugins
# will load all plugin perl modules and build a list of supported