]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1241 in SNORT/snort3 from fix_snort2lua_crash to master
authorMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 30 May 2018 15:57:24 +0000 (11:57 -0400)
committerMichael Altizer (mialtize) <mialtize@cisco.com>
Wed, 30 May 2018 15:57:24 +0000 (11:57 -0400)
Squashed commit of the following:

commit a28c2bb97c2431484abfc120dcabc03b7e8b1ebe
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Fri May 25 14:45:15 2018 -0400

    snort2lua: don't try to index into empty lines

tools/snort2lua/helpers/converter.cc

index 2ee0f47f9879f7e553f407be83267189569b4d1f..66b65a7b3161c3262aa935d4e3e5246a5d776662 100644 (file)
@@ -212,10 +212,14 @@ int Converter::parse_file(
         data_api.set_current_file(input_file); //Set at each line to handle recursion correctly
         data_api.set_current_line(++line_num);
 
-        std::size_t first_non_white_char = tmp.find_first_not_of(' ');
+        if ( tmp.empty() )
+            continue;
+
+        // same critea used for rtrim
+        // http://en.cppreference.com/w/cpp/string/byte/isspace
+        std::size_t first_non_white_char = tmp.find_first_not_of(" \f\n\r\t\v");
 
-        // no, i did not know that semicolons made a line a comment
-        bool comment = (tmp[first_non_white_char] == '#') || (tmp[first_non_white_char] == ';');
+        bool comment = (tmp[first_non_white_char] == '#') or (tmp[first_non_white_char] == ';');
         bool commented_rule = tmp.substr(0, 7) == "# alert";
 
         if ( !commented_rule && ((first_non_white_char == std::string::npos) || comment) )