]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #848 in SNORT/snort3 from Bug185681 to master
authorTom Peters (thopeter) <thopeter@cisco.com>
Thu, 20 Apr 2017 18:14:49 +0000 (14:14 -0400)
committerTom Peters (thopeter) <thopeter@cisco.com>
Thu, 20 Apr 2017 18:14:49 +0000 (14:14 -0400)
Squashed commit of the following:

commit 83b98e57f3c45df9ec66fdc57b1fcb407f203766
Author: allewi <allewi@cisco.com>
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

tools/snort2lua/helpers/converter.cc
tools/snort2lua/helpers/s2l_util.cc
tools/snort2lua/helpers/s2l_util.h
tools/snort2lua/keyword_states/kws_include.cc

index 179ba3e4cb60756f24298a318c30db0890c1faab..ef715b5ec6f5a5a1b7459cc8b5918f00a580e19a 100644 (file)
@@ -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
index a73db427a4b45f6324ba6e329f67b8cb504b5bc5..27d56dddea04c488f91ee362866ec2b774fddfdf 100644 (file)
@@ -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
-
index d7da35a280624fc46e1060bb2178b3eac4c4d2e6..882e191b8b7e12f3377ffa66229bbabd139e1fb7 100644 (file)
@@ -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
index e54459bc617dc8815a9a14fdee99752103331f07..4924cad549503a33e33477333237dad4af3fe02c 100644 (file)
 
 #include <sstream>
 #include <vector>
-
 #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
-