From: Vitalii Izhyk -X (viizhyk - SOFTSERVE INC at Cisco) Date: Tue, 20 Aug 2024 19:50:36 +0000 (+0000) Subject: Pull request #4394: AppId: CSCwk30965: AppIdSessionData causes snort3 to crash. X-Git-Tag: 3.3.4.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab5b206d86d543f892caa996e73dd9eff9c7f3bb;p=thirdparty%2Fsnort3.git Pull request #4394: AppId: CSCwk30965: AppIdSessionData causes snort3 to crash. Merge in SNORT/snort3 from ~VIIZHYK/snort3:viizhyk_CSCwk30965_master to master Squashed commit of the following: commit ce4124066c911c5cbc48f16f2393b7edafe857fa Author: viizhyk Date: Mon Jul 22 19:37:51 2024 -0400 Replaced hsessions vector of raw pointers into vector of smart pointers. Signed-off-by: viizhyk --- diff --git a/src/network_inspectors/appid/appid_session.cc b/src/network_inspectors/appid/appid_session.cc index 26f60442f..bb82f2569 100644 --- a/src/network_inspectors/appid/appid_session.cc +++ b/src/network_inspectors/appid/appid_session.cc @@ -1076,16 +1076,17 @@ void AppIdSession::clear_http_data() AppIdHttpSession* AppIdSession::get_http_session(uint32_t stream_index) const { if (stream_index < api.hsessions.size()) - return api.hsessions[stream_index]; + return api.hsessions[stream_index].get(); else return nullptr; } AppIdHttpSession* AppIdSession::create_http_session(int64_t stream_id) { - AppIdHttpSession* hsession = new AppIdHttpSession(*this, stream_id); - api.hsessions.push_back(hsession); - return hsession; + auto hsession = std::make_unique(*this, stream_id); + auto tmp_hsession = hsession.get(); + api.hsessions.push_back(std::move(hsession)); + return tmp_hsession; } AppIdHttpSession* AppIdSession::get_matching_http_session(int64_t stream_id) const @@ -1093,7 +1094,7 @@ AppIdHttpSession* AppIdSession::get_matching_http_session(int64_t stream_id) con for (uint32_t stream_index=0; stream_index < api.hsessions.size(); stream_index++) { if(stream_id == api.hsessions[stream_index]->get_httpx_stream_id()) - return api.hsessions[stream_index]; + return api.hsessions[stream_index].get(); } return nullptr; } diff --git a/src/network_inspectors/appid/appid_session_api.cc b/src/network_inspectors/appid/appid_session_api.cc index cc5e58e5b..8ebda18dc 100644 --- a/src/network_inspectors/appid/appid_session_api.cc +++ b/src/network_inspectors/appid/appid_session_api.cc @@ -530,7 +530,7 @@ const AppIdHttpSession* AppIdSessionApi::get_matching_http_session(int64_t strea for (uint32_t stream_index=0; stream_index < hsessions.size(); stream_index++) { if(stream_id == hsessions[stream_index]->get_httpx_stream_id()) - return hsessions[stream_index]; + return hsessions[stream_index].get(); } return nullptr; } @@ -538,7 +538,7 @@ const AppIdHttpSession* AppIdSessionApi::get_matching_http_session(int64_t strea AppIdHttpSession* AppIdSessionApi::get_hsession(uint32_t stream_index) const { if (stream_index < hsessions.size()) - return hsessions[stream_index]; + return hsessions[stream_index].get(); else return nullptr; } diff --git a/src/network_inspectors/appid/appid_session_api.h b/src/network_inspectors/appid/appid_session_api.h index e2e0669a0..aee2f93a9 100644 --- a/src/network_inspectors/appid/appid_session_api.h +++ b/src/network_inspectors/appid/appid_session_api.h @@ -173,7 +173,7 @@ private: bool finished : 1; bool user_logged_in : 1; } flags = {}; - std::vector hsessions; + std::vector> hsessions; AppIdDnsSession* dsession = nullptr; snort::SfIp initiator_ip; ServiceAppDescriptor service; @@ -212,8 +212,6 @@ private: void delete_all_http_sessions() { - for (auto hsession : hsessions) - delete hsession; hsessions.clear(); } diff --git a/src/network_inspectors/appid/test/appid_http_event_test.cc b/src/network_inspectors/appid/test/appid_http_event_test.cc index 91f06c112..769846f3b 100644 --- a/src/network_inspectors/appid/test/appid_http_event_test.cc +++ b/src/network_inspectors/appid/test/appid_http_event_test.cc @@ -100,15 +100,13 @@ AppIdHttpSession* AppIdSession::get_http_session(uint32_t stream_index) const { if (stream_index < api.hsessions.size()) { - return api.hsessions[stream_index]; + return api.hsessions[stream_index].get(); } return nullptr; } void AppIdSession::delete_all_http_sessions() { - for (auto hsession : api.hsessions) - delete hsession; api.hsessions.clear(); } diff --git a/src/network_inspectors/appid/test/appid_mock_session.h b/src/network_inspectors/appid/test/appid_mock_session.h index 40b648383..8ed886671 100644 --- a/src/network_inspectors/appid/test/appid_mock_session.h +++ b/src/network_inspectors/appid/test/appid_mock_session.h @@ -172,17 +172,18 @@ AppId AppIdSession::pick_ss_referred_payload_app_id() const AppIdHttpSession* AppIdSession::create_http_session(int64_t) { - AppIdHttpSession* hsession = new MockAppIdHttpSession(*this); - AppidChangeBits change_bits; + auto hsession = std::make_unique(*this); + auto tmp_hsession = hsession.get(); + AppidChangeBits change_bits; hsession->client.set_id(APPID_UT_ID); hsession->client.set_version(APPID_UT_CLIENT_VERSION); change_bits.set(APPID_CLIENT_INFO_BIT); hsession->payload.set_id(APPID_UT_ID); hsession->misc_app_id = APPID_UT_ID; hsession->referred_payload_app_id = APPID_UT_ID; - api.hsessions.push_back(hsession); - return hsession; + api.hsessions.push_back(std::move(hsession)); + return tmp_hsession; } AppIdHttpSession* AppIdSession::get_matching_http_session(int64_t stream_id) const @@ -190,7 +191,7 @@ AppIdHttpSession* AppIdSession::get_matching_http_session(int64_t stream_id) con for (uint64_t stream_index=0; stream_index < api.hsessions.size(); stream_index++) { if (stream_id == api.hsessions[stream_index]->get_httpx_stream_id()) - return api.hsessions[stream_index]; + return api.hsessions[stream_index].get(); } return nullptr; }