[pve-devel] [PATCH common 1/2] Fix 2339: Handle multiple blank lines correctly

Fabian Ebner f.ebner at proxmox.com
Wed Aug 28 11:22:38 CEST 2019


It turns out that the line number counting was also broken (even on files without multiple blanks), since the body of the while inside the nextline subroutine would not be executed for a blank.
I guess the subroutine was intended to skip comments and blanks, but since we use blanks to recognize the end of a section, I changed it to only skip comments.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
Changes from v1:
* fix line number counting
* style

 src/PVE/SectionConfig.pm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm
index dcecce6..a760459 100644
--- a/src/PVE/SectionConfig.pm
+++ b/src/PVE/SectionConfig.pm
@@ -302,13 +302,16 @@ sub parse_config {
     my $lineno = 0;
     my @lines = split(/\n/, $raw);
     my $nextline = sub {
-	while (my $line = shift @lines) {
+	while (defined(my $line = shift @lines)) {
 	    $lineno++;
-	    return $line if $line !~ /^\s*(?:#|$)/;
+	    return $line if ($line !~ /^\s*#/);
 	}
     };
 
-    while (my $line = &$nextline()) {
+    while (@lines) {
+	my $line = $nextline->();
+	next if !$line;
+
 	my $errprefix = "file $filename line $lineno";
 
 	my ($type, $sectionId, $errmsg, $config) = $class->parse_section_header($line);
-- 
2.20.1





More information about the pve-devel mailing list