From 43495f7e562c7e497385873702265ea8b142c9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 1 Sep 2026 22:40:22 -0300 Subject: [PATCH] refactor(xcatd): build the parser of both entry points in one place The module overrides two methods of XML::Simple, one for a recent version and one for an older version, and each built its own parser and set its own handlers. The two bodies were the same apart from spacing, so a change to one refusal had to be repeated in the other, and a reader had to compare them to see that they agreed. Build the parser in one routine that both call. Behaviour does not change. --- xCAT-server/lib/perl/xCAT/XML.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/perl/xCAT/XML.pm b/xCAT-server/lib/perl/xCAT/XML.pm index a570c87fc..42548b487 100644 --- a/xCAT-server/lib/perl/xCAT/XML.pm +++ b/xCAT-server/lib/perl/xCAT/XML.pm @@ -50,9 +50,7 @@ sub build_tree_xml_parser { carp "'nsexpand' option requires XML::SAX"; } - my $xp = XML::Parser->new(Style => 'Tree'); - $xp->setHandlers(ExternEnt => sub { return $_[2] }, - Doctype => sub { croak 'XML document type declaration is not accepted' }); + my $xp = _hardened_parser(); my($tree); if($filename) { # $tree = $xp->parsefile($filename); # Changed due to prob w/mod_perl @@ -68,8 +66,12 @@ sub build_tree_xml_parser { sub new_xml_parser { my($self) = @_; + return _hardened_parser(); +} + +sub _hardened_parser { my $xp = XML::Parser->new(Style => 'Tree'); - $xp->setHandlers(ExternEnt => sub {return $_[2]}, + $xp->setHandlers(ExternEnt => sub { return $_[2] }, Doctype => sub { croak 'XML document type declaration is not accepted' }); return $xp; }