From 5cb09ab21e8b3ddc6ec038c0aaafc48e3cafd693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Wed, 14 Oct 2026 01:15:06 -0300 Subject: [PATCH] fix(tabutils): refuse a tabrestore row with a field after the last column tabrestore stripped the comma after each field, so a comma after the field of the last column left nothing to report. A row with one more empty field was restored as if it fit the columns. A last extra field of 0 also passed, because the check tested the rest of the line for truth. tabrestore now refuses a row whose last column field ends with a comma, or that has any text left, and rolls back the restore. --- xCAT-server/lib/xcat/plugins/tabutils.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index b77c6c464..cc0aab444 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -430,6 +430,7 @@ sub tabrestore my $origline = $line; #save for error reporting my %record; my $col; + my $separated; #a comma after the field of the last column starts one more field foreach $col (@colns) { if ($line =~ /^,/ or $line eq "") @@ -438,7 +439,7 @@ sub tabrestore if (!exists($auto_cols{$col})) { $record{$col} = undef; } - $line =~ s/^,//; + $separated = ($line =~ s/^,//); } elsif ($line =~ /^[^,]*"/) { # We have stuff in quotes... pain... @@ -501,7 +502,7 @@ sub tabrestore elsif ($offset eq length($line) or $nextchar eq ',') { #hit the end of the line or at least the end of the column $ent = substr($line, 0, $offset, ''); - $line =~ s/^,//; + $separated = ($line =~ s/^,//); chop $ent; $ent = substr($ent, 1); $ent =~ s/""/"/g; @@ -531,10 +532,10 @@ sub tabrestore { $record{$col} = $1; } - $line =~ s/^([^,]+)(,|$)//; + $separated = ($line =~ s/^([^,]+)(,|$)//) && $2 eq ','; } } - if ($line) + if ($line ne '' or $separated) { $rollback = 1; $cb->({ error => "Too many fields on line $linenumber: $origline | $line", errorcode => 4 });