From: Shravan Rangarajuvenkata (shrarang) Date: Wed, 14 Aug 2019 18:01:10 +0000 (-0400) Subject: Merge pull request #1710 in SNORT/snort3 from ~SHRARANG/snort3:appid_discovery_ut_fix... X-Git-Tag: 3.0.0-259~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22e7edbc8a8a5c0a225552be792a214c4c6a3bd2;p=thirdparty%2Fsnort3.git Merge pull request #1710 in SNORT/snort3 from ~SHRARANG/snort3:appid_discovery_ut_fix to master Squashed commit of the following: commit 001260b7442e31e52de22676a5fe9a28f5f69f9c Author: Shravan Rangaraju Date: Wed Aug 14 11:07:07 2019 -0400 appid: fix discovery unit test that was failing intermittently --- diff --git a/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc b/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc index 5b7f4b479..ceaf04c5b 100644 --- a/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc +++ b/src/network_inspectors/appid/detector_plugins/http_url_patterns.cc @@ -800,9 +800,9 @@ void HttpPatternMatchers::get_http_offsets(snort::Packet* pkt, AppIdHttpSession* for (int fieldId = REQ_AGENT_FID; fieldId <= REQ_COOKIE_FID; fieldId++) { - pair_t off; - if ( hsession->get_offset(fieldId, off.first, off.second) ) - hsession->set_offset(fieldId, 0, off.second); + pair_t off; + if ( hsession->get_offset(fieldId, off.first, off.second) ) + hsession->set_offset(fieldId, 0, off.second); } if (!pkt->data || pkt->dsize < MIN_HTTP_REQ_HEADER_SIZE) diff --git a/src/network_inspectors/appid/lua_detector_api.cc b/src/network_inspectors/appid/lua_detector_api.cc index b45baa028..c95d05e5f 100644 --- a/src/network_inspectors/appid/lua_detector_api.cc +++ b/src/network_inspectors/appid/lua_detector_api.cc @@ -2623,24 +2623,24 @@ LuaServiceObject::LuaServiceObject(AppIdDiscovery* sdm, const std::string& detec } else { - AppIdDetector *ad = nullptr; - AppIdDetectors *appid_detectors = nullptr; + AppIdDetector *ad = nullptr; + AppIdDetectors *appid_detectors = nullptr; - if (protocol == IpProtocol::TCP) + if (protocol == IpProtocol::TCP) { appid_detectors = ServiceDiscovery::get_instance().get_tcp_detectors(); - auto detector = appid_detectors->find(detector_name); + auto detector = appid_detectors->find(detector_name); if (detector != appid_detectors->end()) ad = detector->second; } - else if (protocol == IpProtocol::UDP) + else if (protocol == IpProtocol::UDP) { appid_detectors = ServiceDiscovery::get_instance().get_udp_detectors(); - auto detector = appid_detectors->find(detector_name); + auto detector = appid_detectors->find(detector_name); if (detector != appid_detectors->end()) ad = detector->second; } - sd = (ServiceDetector*)ad; + sd = (ServiceDetector*)ad; } UserData::push(L, DETECTOR, this); @@ -2693,24 +2693,24 @@ LuaClientObject::LuaClientObject(AppIdDiscovery* cdm, const std::string& detecto } else { - AppIdDetector *ad = nullptr; - AppIdDetectors *appid_detectors = nullptr; + AppIdDetector *ad = nullptr; + AppIdDetectors *appid_detectors = nullptr; - if (protocol == IpProtocol::TCP) + if (protocol == IpProtocol::TCP) { appid_detectors = ClientDiscovery::get_instance().get_tcp_detectors(); - auto detector = appid_detectors->find(detector_name); + auto detector = appid_detectors->find(detector_name); if (detector != appid_detectors->end()) ad = detector->second; } - else if (protocol == IpProtocol::UDP) + else if (protocol == IpProtocol::UDP) { appid_detectors = ClientDiscovery::get_instance().get_udp_detectors(); - auto detector = appid_detectors->find(detector_name); + auto detector = appid_detectors->find(detector_name); if (detector != appid_detectors->end()) ad = detector->second; } - cd = (ClientDetector*)ad; + cd = (ClientDetector*)ad; } UserData::push(L, DETECTOR, this); diff --git a/src/network_inspectors/appid/service_plugins/service_ftp.cc b/src/network_inspectors/appid/service_plugins/service_ftp.cc index ff65e735e..600417a89 100644 --- a/src/network_inspectors/appid/service_plugins/service_ftp.cc +++ b/src/network_inspectors/appid/service_plugins/service_ftp.cc @@ -432,9 +432,9 @@ static int ftp_validate_reply(const uint8_t* data, uint16_t& offset, { fd.rstate = FTP_REPLY_MID; if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_MULTI)) - return -1; + return -1; if (fd.rstate == FTP_REPLY_MID) - fd.rstate = FTP_REPLY_LONG; + fd.rstate = FTP_REPLY_LONG; } else { @@ -456,36 +456,36 @@ static int ftp_validate_reply(const uint8_t* data, uint16_t& offset, tmp_state = fd.rstate; fd.rstate = FTP_REPLY_MID; if (ftp_parse_response(data, offset, size, fd, tmp_state)) - return -1; + return -1; if (fd.rstate == FTP_REPLY_MID) - fd.rstate = FTP_REPLY_LONG; + fd.rstate = FTP_REPLY_LONG; } break; case FTP_REPLY_LONG: fd.rstate = FTP_REPLY_MID; - if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_LONG)) - return -1; + if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_LONG)) + return -1; if (++offset >= size) { fd.rstate = FTP_REPLY_BEGIN; break; } - if (fd.rstate == FTP_REPLY_MID) - { + if (fd.rstate == FTP_REPLY_MID) + { fd.rstate = FTP_REPLY_LONG; - break; - } + break; + } if (size - offset < (int)sizeof(ServiceFTPCode)) { - fd.rstate = FTP_REPLY_MID; - if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_LONG)) - return -1; + fd.rstate = FTP_REPLY_MID; + if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_LONG)) + return -1; if (fd.rstate == FTP_REPLY_MID) fd.rstate = FTP_REPLY_LONG; } else - { - code_hdr = (const ServiceFTPCode*)(data + offset); + { + code_hdr = (const ServiceFTPCode*)(data + offset); if(code_hdr->code[0] >= '1' and code_hdr->code[0] <= '5' and code_hdr->code[1] >= '1' and code_hdr->code[1] <= '5' and isdigit(code_hdr->code[2])) @@ -496,23 +496,23 @@ static int ftp_validate_reply(const uint8_t* data, uint16_t& offset, if (tmp == fd.code) { offset += sizeof(ServiceFTPCode); - if (code_hdr->sp == ' ' or code_hdr->sp == 0x09) - { - fd.rstate = FTP_REPLY_MID; - if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_BEGIN)) - return -1; - } - else if (code_hdr->sp == '-') - { - fd.rstate = FTP_REPLY_MID; - if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_MULTI)) - return -1; - } - if (fd.rstate == FTP_REPLY_MID) + if (code_hdr->sp == ' ' or code_hdr->sp == 0x09) + { + fd.rstate = FTP_REPLY_MID; + if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_BEGIN)) + return -1; + } + else if (code_hdr->sp == '-') + { + fd.rstate = FTP_REPLY_MID; + if (ftp_parse_response(data, offset, size, fd, FTP_REPLY_MULTI)) + return -1; + } + if (fd.rstate == FTP_REPLY_MID) fd.rstate = FTP_REPLY_LONG; } } - } + } break; default: return -1; diff --git a/src/network_inspectors/appid/test/appid_mock_session.h b/src/network_inspectors/appid/test/appid_mock_session.h index 5bc9334bc..67ac6f9c6 100644 --- a/src/network_inspectors/appid/test/appid_mock_session.h +++ b/src/network_inspectors/appid/test/appid_mock_session.h @@ -68,13 +68,14 @@ public: } }; -AppIdSession::AppIdSession(IpProtocol, const SfIp*, uint16_t, AppIdInspector& inspector) - : FlowData(inspector_id, &inspector) +AppIdSession::AppIdSession(IpProtocol proto, const SfIp*, uint16_t, AppIdInspector& inspector) + : FlowData(inspector_id, &inspector), protocol(proto) { common.flow_type = APPID_FLOW_TYPE_NORMAL; service_port = APPID_UT_SERVICE_PORT; AppidChangeBits change_bits; + memset(application_ids, 0, sizeof(application_ids)); client.update_user(APPID_UT_ID, APPID_UT_USERNAME); client.set_version(APPID_UT_CLIENT_VERSION, change_bits);