From a4e7e481c6cb5e97eb9373b4fc01754e4e975dd2 Mon Sep 17 00:00:00 2001 From: "Jason D. Kelleher" Date: Sat, 16 Jan 2021 17:19:41 -0500 Subject: [PATCH] strip comments during the initial read to prevent processing commented out include and directory statements --- mkrdns | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mkrdns b/mkrdns index 82ab080..600f176 100755 --- a/mkrdns +++ b/mkrdns @@ -164,6 +164,18 @@ READCONF: { my ($config); open( CONF, "<$bootfile" ) || die "(fatal) Can't open $bootfile:$!"; while ( $_ = ) { # deal with the includes! + + # Must strip comments during the initial read to prevent processing commented out + # include and directory statements. Order is important here. + $_ =~ s!/\*.*\*/!!g; # /* ... Strip single-line C-style comments */ + if ( $_ =~ s!/\*.*$!! ) { # /* ... Strip mulit-line + while ( $_ = ) { # C-style comments */ + last if ( $_ =~ s!.*\*/!! ); + } + } + $_ =~ s!//.*!!; # // ... Strip C++ style comments + $_ =~ s!#.*!!; # # ... Strip shell-style comments + if ( ( /^directory/i && $type eq "boot" ) || ( /\bdirectory\s+"[^"]+";/ && $type eq "conf" ) ) { @@ -179,6 +191,18 @@ READCONF: { # (boot) ^include # (conf) ^include ""; for ( my ($i) = 0 ; $i <= $#conf ; $i++ ) { + + # Must strip comments during the initial read to prevent processing commented out + # include and directory statements. Order is important here. + $_ =~ s!/\*.*\*/!!g; # /* ... Strip single-line C-style comments */ + if ( $_ =~ s!/\*.*$!! ) { # /* ... Strip mulit-line + while ( $_ = ) { # C-style comments */ + last if ( $_ =~ s!.*\*/!! ); + } + } + $_ =~ s!//.*!!; # // ... Strip C++ style comments + $_ =~ s!#.*!!; # # ... Strip shell-style comments + next unless ( $conf[$i] =~ /\binclude\s/i ); # skip non includes ... chomp $conf[$i];