From: Mike Stepanek (mstepane) Date: Tue, 12 Feb 2019 17:30:41 +0000 (-0500) Subject: Merge pull request #1511 in SNORT/snort3 from ~SHRARANG/snort3:appid_suppress_detecto... X-Git-Tag: 3.0.0-251~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d50bf92b31002fdd1e5db7b689dbe7c8f77b55c;p=thirdparty%2Fsnort3.git Merge pull request #1511 in SNORT/snort3 from ~SHRARANG/snort3:appid_suppress_detector_warning to master Squashed commit of the following: commit c77afdcab87783dbd803f461fa12d36abdf2fefb Author: Shravan Rangaraju Date: Mon Feb 11 23:21:43 2019 -0500 appid: skip empty detectors --- diff --git a/src/network_inspectors/appid/lua_detector_module.cc b/src/network_inspectors/appid/lua_detector_module.cc index 5974ec2e0..b52240c58 100644 --- a/src/network_inspectors/appid/lua_detector_module.cc +++ b/src/network_inspectors/appid/lua_detector_module.cc @@ -29,6 +29,7 @@ #include #include +#include #include "appid_config.h" #include "lua_detector_util.h" @@ -40,6 +41,7 @@ #include "log/messages.h" using namespace snort; +using namespace std; #define MAX_LUA_DETECTOR_FILENAME_LEN 1024 #define MAX_DEFAULT_NUM_LUA_TRACKERS 10000 @@ -185,7 +187,7 @@ LuaDetectorManager::~LuaDetectorManager() lsd->package_info.name.c_str(), lua_tostring(L, -1)); } } - delete lua_object; + delete lua_object; } lua_close(L); } @@ -290,7 +292,7 @@ static inline uint32_t compute_lua_tracker_size(uint64_t rnaMemory, uint32_t num } // Leaves 1 value (the Detector userdata) at the top of the stack when succeeds -static LuaObject* create_lua_detector(lua_State* L, const char* detector_name, bool is_custom) +static LuaObject* create_lua_detector(lua_State* L, const char* detector_name, bool is_custom, const char* detector_filename) { std::string log_name; IpProtocol proto = IpProtocol::PROTO_NOT_SET; @@ -302,8 +304,18 @@ static LuaObject* create_lua_detector(lua_State* L, const char* detector_name, b if (!lua_istable(L, -1)) { if (init(L)) // for control thread only - ErrorMessage("Error - appid: can not read DetectorPackageInfo table from %s\n", - detector_name); + { + ifstream detector_file; + + // Skip file if empty + detector_file.open(detector_filename); + detector_file >> ws; + int c = detector_file.peek(); + detector_file.close(); + if (c != EOF) + ErrorMessage("Error - appid: can not read DetectorPackageInfo table from %s\n", + detector_name); + } if (!lua_isnil(L, -1)) // pop DetectorPackageInfo index if it was pushed lua_pop(L, 1); return nullptr; @@ -396,7 +408,7 @@ void LuaDetectorManager::load_detector(char* detector_filename, bool isCustom) return; } - LuaObject* lua_object = create_lua_detector(L, detectorName, isCustom); + LuaObject* lua_object = create_lua_detector(L, detectorName, isCustom, detector_filename); if (lua_object) allocated_objects.push_front(lua_object); } @@ -466,7 +478,7 @@ void LuaDetectorManager::activate_lua_detectors() //FIXIT-M: RELOAD - use lua references to get user data object from stack /*first parameter is DetectorUserData */ std::string name = lsd->package_info.name + "_"; - lua_getglobal(L, name.c_str()); + lua_getglobal(L, name.c_str()); /*second parameter is a table containing configuration stuff. */ lua_newtable(L);