2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-21 09:52:17 +00:00

fix(boot): bound recursive node-template replacements

This commit is contained in:
Vinícius Ferrão
2026-10-26 17:44:52 -03:00
parent 3b60ea3150
commit a09fd53acd
+12
View File
@@ -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);