]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4394: AppId: CSCwk30965: AppIdSessionData causes snort3 to crash.
authorVitalii Izhyk -X (viizhyk - SOFTSERVE INC at Cisco) <viizhyk@cisco.com>
Tue, 20 Aug 2024 19:50:36 +0000 (19:50 +0000)
committerChris Sherwin (chsherwi) <chsherwi@cisco.com>
Tue, 20 Aug 2024 19:50:36 +0000 (19:50 +0000)
Merge in SNORT/snort3 from ~VIIZHYK/snort3:viizhyk_CSCwk30965_master to master

Squashed commit of the following:

commit ce4124066c911c5cbc48f16f2393b7edafe857fa
Author: viizhyk <viizhyk@cisco.com>
Date:   Mon Jul 22 19:37:51 2024 -0400

    Replaced hsessions vector of raw pointers into vector of smart pointers.

Signed-off-by: viizhyk <viizhyk@cisco.com>
src/network_inspectors/appid/appid_session.cc
src/network_inspectors/appid/appid_session_api.cc
src/network_inspectors/appid/appid_session_api.h
src/network_inspectors/appid/test/appid_http_event_test.cc
src/network_inspectors/appid/test/appid_mock_session.h

index 26f60442f51bf360fcb0f47cb34f357db04e627d..bb82f256972b2ff001ab8894e4947265479e7323 100644 (file)
@@ -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<AppIdHttpSession>(*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;
 }
index cc5e58e5b22d8b2d78227dd2e8ababb9cce03af1..8ebda18dc3e48e3b7c94b2cadf1f4888cf11eb6b 100644 (file)
@@ -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;
 }
index e2e0669a0a222bf866fffb1a70fde92809f7a4cd..aee2f93a9f9efcdf44f1579851e56f80d767c01f 100644 (file)
@@ -173,7 +173,7 @@ private:
         bool finished : 1;
         bool user_logged_in : 1;
     } flags = {};
-    std::vector<AppIdHttpSession*> hsessions;
+    std::vector<std::unique_ptr<AppIdHttpSession>> 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();
     }
 
index 91f06c11287b4b9c23674aa4fd2ff82e7832ce28..769846f3bdcfc64bd5db9838e8ffe6a31c8b661d 100644 (file)
@@ -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();
 }
 
index 40b64838347f05f0948bf36e58337fb0d596c589..8ed886671391443de42767bec72edccae235e82c 100644 (file)
@@ -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<MockAppIdHttpSession>(*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;
 }