diff --git a/perl-xCAT/xCAT/BootUtils.pm b/perl-xCAT/xCAT/BootUtils.pm index 98e3654ed3..95399a3ee8 100644 --- a/perl-xCAT/xCAT/BootUtils.pm +++ b/perl-xCAT/xCAT/BootUtils.pm @@ -47,13 +47,25 @@ sub expand_node_template { my ($node, $text, $on_error) = @_; return $text unless defined($text); + # Each initial token contributes to its pass's shared replacement budget. + my $replacements_per_token = 16; + my $remaining = $replacements_per_token * (() = $text =~ /#NODEATTRIB:[^:#]+:[^:#]+#/g); while ($text =~ /#NODEATTRIB:([^:#]+):([^:#]+)#/) { + unless ($remaining--) { + $on_error->("Node template expansion exceeded its replacement limit at #NODEATTRIB:$1:$2#"); + return; + } my $table = xCAT::Table->new($1); my $entry = $table->getNodeAttribs($node, [$2]); my $value = $entry->{$2} // ''; $text =~ s/#NODEATTRIB:([^:#]+):([^:#]+)#/$value/; } + $remaining = $replacements_per_token * (() = $text =~ /#TABLE:[^:#]+:[^:#]+:[^:#]+#/g); while ($text =~ /#TABLE:([^:#]+):([^:#]+):([^:#]+)#/) { + unless ($remaining--) { + $on_error->("Node template expansion exceeded its replacement limit at #TABLE:$1:$2:$3#"); + return; + } my ($table_name, $key, $column) = ($1, $2, $3); if ($key =~ /THISNODE/ or $key =~ /\$NODE/) { my $table = xCAT::Table->new($table_name);