]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1710 in SNORT/snort3 from ~SHRARANG/snort3:appid_discovery_ut_fix...
authorShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Wed, 14 Aug 2019 18:01:10 +0000 (14:01 -0400)
committerShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Wed, 14 Aug 2019 18:01:10 +0000 (14:01 -0400)
Squashed commit of the following:

commit 001260b7442e31e52de22676a5fe9a28f5f69f9c
Author: Shravan Rangaraju <shrarang@cisco.com>
Date:   Wed Aug 14 11:07:07 2019 -0400

    appid: fix discovery unit test that was failing intermittently

src/network_inspectors/appid/detector_plugins/http_url_patterns.cc
src/network_inspectors/appid/lua_detector_api.cc
src/network_inspectors/appid/service_plugins/service_ftp.cc
src/network_inspectors/appid/test/appid_mock_session.h

index 5b7f4b479b2b62fddb499bff8c65dbdf2b29e451..ceaf04c5b4059b970f306adc1af00648cbdb4e4c 100644 (file)
@@ -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)
index b45baa02821d51f12f91c0372dbc13ea69818b0e..c95d05e5ffb750c4bf128fd926293a76c6ac8dbb 100644 (file)
@@ -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<LuaServiceObject>::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<LuaClientObject>::push(L, DETECTOR, this);
index ff65e735eac4267203e1427c42b78ca09a5ed6d1..600417a89bf4f26a548aedd4b247d0f7f1667b08 100644 (file)
@@ -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;
index 5bc9334bcef10a5c4cce7b03146a9c6817f5fcf0..67ac6f9c6ed5a7ecfa001e4e7461a4ab7402224e 100644 (file)
@@ -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);