]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #735 in SNORT/snort3 from sip_strings to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 6 Dec 2016 15:11:37 +0000 (10:11 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Tue, 6 Dec 2016 15:11:37 +0000 (10:11 -0500)
Squashed commit of the following:

commit fa7daec1f2e0064bc4cd14cafe028bfedf0d8c9e
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Mon Dec 5 14:28:22 2016 -0500

    added copies to sip detector so strings are valid after the current packet disappears

commit 35bb540e26ed79d50a0f00299b9d993dde1cbc7d
Author: Carter Waxman <cwaxman@cisco.com>
Date:   Fri Dec 2 16:04:17 2016 -0500

    all SipEvent strings now handled wih char arrays

src/network_inspectors/appid/detector_plugins/detector_sip.cc
src/pub_sub/sip_events.cc
src/pub_sub/sip_events.h

index 9c7df29e64bf7edb89b984399163d811c7237aac..6f4f98941700ebfe68752bc8ee85b03ab7b83a34 100644 (file)
@@ -92,9 +92,9 @@ struct ClientSIPData
     void* owner = nullptr;
     SIPState state = SIP_STATE_INIT;
     uint32_t flags = 0;
-    const string* user_name = nullptr;
-    const string* client_user_agent = nullptr;
-    const string* from = nullptr;
+    string user_name;
+    string user_agent;
+    string from;
 };
 
 struct DetectorSipConfig
@@ -557,24 +557,24 @@ static void SipSessionCbClientProcess(SipEvent& event, AppIdSession* asd)
 
     if( event.is_invite() && direction == APP_ID_FROM_INITIATOR )
     {
-        fd->from = event.get_from();
-        fd->user_name = event.get_user_name();
-        fd->client_user_agent = event.get_user_agent();
+        fd->from = string(event.get_from(), event.get_from_len());
+        fd->user_name = string(event.get_user_name(), event.get_user_name_len());
+        fd->user_agent = string(event.get_user_agent(), event.get_user_agent_len());
     }
 
-    if( fd->client_user_agent )
+    if( fd->user_agent.size() )
     {
         if( get_sip_client_app(detector_sip_config.sip_ua_matcher,
-            fd->client_user_agent->c_str(), fd->client_user_agent->size(), &ClientAppId, &clientVersion) )
+            fd->user_agent.c_str(), fd->user_agent.size(), &ClientAppId, &clientVersion) )
             goto success;
     }
 
-    if( fd->from && !(fd->flags & SIP_FLAG_SERVER_CHECKED) )
+    if( fd->from.size() && !(fd->flags & SIP_FLAG_SERVER_CHECKED) )
     {
         fd->flags |= SIP_FLAG_SERVER_CHECKED;
 
         if( get_sip_client_app(detector_sip_config.sip_server_matcher,
-            fd->from->c_str(), fd->from->size(), &ClientAppId, &clientVersion) )
+            fd->from.c_str(), fd->from.size(), &ClientAppId, &clientVersion) )
             goto success;
     }
 
@@ -586,8 +586,8 @@ success:
     sip_udp_client_mod.api->add_app(asd, APP_ID_SIP, ClientAppId, clientVersion);
     appid_stats.sip_clients++;
 
-    if( fd->user_name )
-        sip_udp_client_mod.api->add_user(asd, fd->user_name->c_str(), APP_ID_SIP, 1);
+    if( fd->user_name.size() )
+        sip_udp_client_mod.api->add_user(asd, fd->user_name.c_str(), APP_ID_SIP, 1);
 
     asd->set_session_flags(APPID_SESSION_CLIENT_DETECTED);
 }
@@ -612,15 +612,15 @@ static void SipSessionCbServiceProcess(SipEvent& event, AppIdSession* asd)
     {
         if( event.get_user_agent() )
         {
-            memcpy(ss->vendor, event.get_user_agent()->c_str(),
-                event.get_user_agent()->size() > (MAX_VENDOR_SIZE - 1) ?  (MAX_VENDOR_SIZE - 1) :
-                event.get_user_agent()->size());
+            memcpy(ss->vendor, event.get_user_agent(),
+                event.get_user_agent_len() > (MAX_VENDOR_SIZE - 1) ?  (MAX_VENDOR_SIZE - 1) :
+                event.get_user_agent_len());
         }
         else if( event.get_server() )
         {
-            memcpy(ss->vendor, event.get_server()->c_str(),
-                event.get_server()->size() > (MAX_VENDOR_SIZE - 1) ?  (MAX_VENDOR_SIZE - 1) :
-                event.get_server()->size());
+            memcpy(ss->vendor, event.get_server(),
+                event.get_server_len() > (MAX_VENDOR_SIZE - 1) ?  (MAX_VENDOR_SIZE - 1) :
+                event.get_server_len());
         }
     }
 
index 890589972bc98cebe04b061764fd70f129c3fc61..8c96ad7e9dc2a032429a4883ff4928c69ccaab3d 100644 (file)
@@ -30,17 +30,14 @@ SipEvent::SipEvent(const Packet* p, const SIPMsg* msg, const SIP_DialogData* dia
     this->msg = msg;
     this->dialog = dialog;
 
-    if( msg->fromLen )
-        from = string(msg->from, msg->fromLen);
-
-    if( msg->userNameLen )
-        user_name = string(msg->userName, msg->userNameLen);
-
-    if( msg->userAgentLen )
-        user_agent = string(msg->userAgent, msg->userAgentLen);
-
-    if( msg->serverLen )
-        server = string(msg->server, msg->serverLen);
+    from = msg->from;
+    from_len = msg->fromLen;
+    user_name = msg->userName;
+    user_name_len = msg->userNameLen;
+    user_agent = msg->userAgent;
+    user_agent_len = msg->userAgentLen;
+    server = msg->server;
+    server_len = msg->serverLen;
 }
 
 SipEvent::~SipEvent()
index 2b559ddce07e390d9e633a69ea63995f32577c60..1f0c46e70efb681a9273effa3af28805fed18491 100644 (file)
@@ -82,17 +82,29 @@ public:
     const Packet* get_packet() override
     { return p; }
 
-    const std::string* get_from() const
-    { return from.size() ? &from : nullptr; }
+    const char* get_from() const
+    { return from; }
 
-    const std::string* get_user_name() const
-    { return user_name.size() ? &user_name : nullptr; }
+    size_t get_from_len() const
+    { return from_len; }
 
-    const std::string* get_user_agent() const
-    { return user_agent.size() ? &user_agent : nullptr; }
+    const char* get_user_name() const
+    { return user_name; }
 
-    const std::string* get_server() const
-    { return server.size() ? &server : nullptr; }
+    size_t get_user_name_len() const
+    { return user_name_len; }
+
+    const char* get_user_agent() const
+    { return user_agent; }
+
+    size_t get_user_agent_len() const
+    { return user_agent_len; }
+
+    const char* get_server() const
+    { return server; }
+
+    size_t get_server_len() const
+    { return server_len; }
 
     bool is_invite() const;
     bool is_media_updated() const;
@@ -108,10 +120,14 @@ private:
     const SIPMsg* msg;
     const SIP_DialogData* dialog;
 
-    std::string from;
-    std::string user_name;
-    std::string user_agent;
-    std::string server;
+    const char* from;
+    size_t from_len;
+    const char* user_name;
+    size_t user_name_len;
+    const char* user_agent;
+    size_t user_agent_len;
+    const char* server;
+    size_t server_len;
 
     std::list<SipEventMediaSession*> sessions;
     SIP_MediaSession* current_media_session = nullptr;