From: Tom Peters (thopeter) Date: Thu, 20 Apr 2017 18:14:49 +0000 (-0400) Subject: Merge pull request #848 in SNORT/snort3 from Bug185681 to master X-Git-Tag: 3.0.0-233~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9967f6acb620917b609b1c46292d7efb816b0a99;p=thirdparty%2Fsnort3.git Merge pull request #848 in SNORT/snort3 from Bug185681 to master Squashed commit of the following: commit 83b98e57f3c45df9ec66fdc57b1fcb407f203766 Author: allewi Date: Wed Apr 12 09:53:36 2017 -0400 fix is for snort2lua hanging on bad include statements and to always print rej file on error. removing trailing space and the blank line removed another space --- diff --git a/tools/snort2lua/helpers/converter.cc b/tools/snort2lua/helpers/converter.cc index 179ba3e4c..ef715b5ec 100644 --- a/tools/snort2lua/helpers/converter.cc +++ b/tools/snort2lua/helpers/converter.cc @@ -383,8 +383,16 @@ int Converter::convert(std::string input, std::size_t errors = data_api.num_errors() + rule_api.num_errors(); std::cerr << "ERROR: " << errors << " errors occurred while converting\n"; std::cerr << "ERROR: see " << error_file << " for details" << std::endl; - } + std::ofstream rejects; // in this case, rejects are regular configuration options + rejects.open(error_file, std::ifstream::out); - return rc; -} + if (data_api.failed_conversions()) + data_api.print_errors(rejects); + if (rule_api.failed_conversions()) + rule_api.print_rejects(rejects); + + rejects.close(); + } + return rc; +} \ No newline at end of file diff --git a/tools/snort2lua/helpers/s2l_util.cc b/tools/snort2lua/helpers/s2l_util.cc index a73db427a..27d56ddde 100644 --- a/tools/snort2lua/helpers/s2l_util.cc +++ b/tools/snort2lua/helpers/s2l_util.cc @@ -308,6 +308,16 @@ bool file_exists(const std::string& name) return (stat (name.c_str(), &buffer) == 0); } +bool is_regular_file(std::string& path) +{ + struct stat s; + + if (stat(path.c_str(), &s) == 0) + return (s.st_mode & S_IFREG); + + return false; +} + bool case_compare(std::string arg1, std::string arg2) { std::transform(arg1.begin(), arg1.end(), arg1.begin(), ::tolower); @@ -318,4 +328,3 @@ bool case_compare(std::string arg1, std::string arg2) return false; } } // namespace util - diff --git a/tools/snort2lua/helpers/s2l_util.h b/tools/snort2lua/helpers/s2l_util.h index d7da35a28..882e191b8 100644 --- a/tools/snort2lua/helpers/s2l_util.h +++ b/tools/snort2lua/helpers/s2l_util.h @@ -111,7 +111,7 @@ std::string& sanitize_lua_string(std::string& s); std::size_t get_substr_length(std::string s, std::size_t max_length); bool case_compare(std::string, std::string); +bool is_regular_file(std::string& path); } // namespace util -#endif - +#endif \ No newline at end of file diff --git a/tools/snort2lua/keyword_states/kws_include.cc b/tools/snort2lua/keyword_states/kws_include.cc index e54459bc6..4924cad54 100644 --- a/tools/snort2lua/keyword_states/kws_include.cc +++ b/tools/snort2lua/keyword_states/kws_include.cc @@ -19,12 +19,12 @@ #include #include - #include "conversion_state.h" #include "helpers/converter.h" #include "helpers/s2l_util.h" #include "helpers/parse_cmd_line.h" #include "data/data_types/dt_comment.h" +#include "keywords_api.h" namespace keywords { @@ -51,17 +51,23 @@ bool Include::convert(std::istringstream& data_stream) std::string full_file = data_api.expand_vars(file); std::string tmp = full_file; // for the error message + //check if the file exists using what was provided + //if not use the conf_dir with the file if (!util::file_exists(full_file)) full_file = parser::get_conf_dir() + full_file; - // if we still can't find this file, add it as a snort file - if (util::file_exists(full_file)) - return !(cv.parse_include_file(full_file)); - - std::string error_string = "Can't find file " + file + ". " - " Searched locations: " + tmp + ", " + full_file; + // make sure its a regular file (not a directory) + if (util::is_regular_file(full_file)) + { + return !cv.parse_include_file(full_file); + } + else + { //cant find it .. log error + std::string error_string = "Can't find file " + file + ". " + " Searched locations: [" + tmp + "], [" + full_file + "]"; - data_api.failed_conversion(data_stream, error_string); + data_api.failed_conversion(data_stream, error_string); + } } } else @@ -70,7 +76,6 @@ bool Include::convert(std::istringstream& data_stream) "'filename' argument"); } - rule_api.include_rule_file(file); return false; } @@ -89,4 +94,3 @@ static const ConvertMap keyword_include = const ConvertMap* include_map = &keyword_include; } // namespace keywords -