]> granicus.if.org Git - pdns/commitdiff
Strip # only when preceded with whitespace or start of line
authorAki Tuomi <cmouse@desteem.org>
Sun, 5 Apr 2015 14:42:16 +0000 (17:42 +0300)
committerAki Tuomi <cmouse@desteem.org>
Sun, 5 Apr 2015 14:42:16 +0000 (17:42 +0300)
pdns/arguments.cc

index 6278dadaad3317285e1537523a6be64ab1a7a33f..664207e6b283b66f49b27aa34efa81183d6c101d 100644 (file)
@@ -404,8 +404,12 @@ bool ArgvMap::preParseFile(const char *fname, const string &arg, const string& t
       line+=pline;
 
     // strip everything after a #
-    if((pos=line.find("#"))!=string::npos)
-      line=line.substr(0,pos);
+    if((pos=line.find("#"))!=string::npos) {
+      // make sure it's either first char or has whitespace before
+      // fixes issue #354
+      if (pos == 0 || std::isspace(line[pos-1]))
+        line=line.substr(0,pos);
+    }
 
     // strip trailing spaces
     trim_right(line);
@@ -457,8 +461,12 @@ bool ArgvMap::file(const char *fname, bool lax, bool included)
       line+=pline;
 
     // strip everything after a #
-    if((pos=line.find("#"))!=string::npos)
-      line=line.substr(0,pos);
+    if((pos=line.find("#"))!=string::npos) {
+      // make sure it's either first char or has whitespace before
+      // fixes issue #354
+      if (pos == 0 || std::isspace(line[pos-1]))
+        line=line.substr(0,pos);
+    }
 
     // strip trailing spaces
     trim(line);