]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
more FIXITs
authorRuss Combs <rucombs@cisco.com>
Tue, 26 Aug 2014 17:54:09 +0000 (13:54 -0400)
committerRuss Combs <rucombs@cisco.com>
Tue, 26 Aug 2014 17:54:09 +0000 (13:54 -0400)
src/ips_options/ips_pcre.cc
src/network_inspectors/binder/bind_module.cc
src/network_inspectors/binder/binder.cc
src/network_inspectors/binder/binder.h
src/parser/parse_stream.cc

index c060dfb10cfa6e6fa9be738c8532551a40b73eeb..817a7970f310d13b47f4778f0f8251f6c7148bcd 100644 (file)
@@ -329,6 +329,10 @@ static void pcre_parse(const char* data, PcreData* pcre_data)
  syntax:
     free(free_me);
 
+    // ensure integrity from parse error to fatal error
+    if ( !pcre_data->expression )
+        pcre_data->expression = SnortStrdup("");
+
     ParseError("unable to parse pcre regex %s", data);
 }
 
index f581db39febac3c74ae53dd8b3db62ebc0caddd1..1edb13bb849df4206dbf059ae48b0e6fc4bf9bf5 100644 (file)
@@ -28,6 +28,7 @@
 using namespace std;
 
 #include "binder.h"
+#include "protocols/packet.h"
 
 THREAD_LOCAL SimpleStats bstats;
 
@@ -127,8 +128,13 @@ bool BinderModule::set(const char* fqn, Value& v, SnortConfig*)
         work->nets = v.get_string();
 
     else if ( v.is("proto") )
-        work->proto = (BindProto)v.get_long();
-
+    {
+        const unsigned mask[] =
+        { 
+            PROTO_BIT__ALL, PROTO_BIT__IP, PROTO_BIT__ICMP, PROTO_BIT__TCP, PROTO_BIT__UDP
+        };
+        work->protos = mask[v.get_long()];
+    }
     else if ( v.is("ports") )
         v.get_bits(work->ports);
 
index c0d2048695e615d5632689805451c19517dacca1..8744f7802614a128d5ccb778c3e5dd006bf3819c 100644 (file)
@@ -47,7 +47,7 @@ THREAD_LOCAL ProfileStats bindPerfStats;
 Binding::Binding()
 {
     role = BR_EITHER;
-    proto = BP_ANY;
+    protos = PROTO_BIT__ALL;
     action = BA_INSPECT;
     ports.set();
 }
@@ -73,18 +73,18 @@ static void set_session(Flow* flow)
     flow->clouseau = nullptr;
 }
 
-// FIXIT-H use IPPROTO_* directly (any == 0)
-static bool check_proto(const Flow* flow, BindProto bp)
+static bool check_proto(const Flow* flow, unsigned mask)
 {
-    switch ( bp )
+    unsigned bit = 0;
+
+    switch ( flow->protocol )
     {
-    case BP_ANY: return true;
-    case BP_IP:  return flow->protocol == IPPROTO_IP;
-    case BP_ICMP:return flow->protocol == IPPROTO_ICMP;
-    case BP_TCP: return flow->protocol == IPPROTO_TCP;
-    case BP_UDP: return flow->protocol == IPPROTO_UDP;
+    case IPPROTO_IP:   bit = PROTO_BIT__IP;   break;
+    case IPPROTO_ICMP: bit = PROTO_BIT__ICMP; break;
+    case IPPROTO_TCP:  bit = PROTO_BIT__TCP;  break;
+    case IPPROTO_UDP:  bit = PROTO_BIT__UDP;  break;
     }
-    return false;
+    return ( mask & bit ) != 0;
 }
 
 //-------------------------------------------------------------------------
@@ -195,7 +195,7 @@ int Binder::check_rules(Flow* flow, Packet* p)
     {
         pb = bindings[i];
 
-        if ( !check_proto(flow, pb->proto) )
+        if ( !check_proto(flow, pb->protos) )
             continue;
 
         if ( pb->ports.test(port) )
index 7e91d7b6a79ff64b0e0c2223169c18a1955c0e68..ecb0767551b6177cf3e135066f2b4d6e12898ea9 100644 (file)
@@ -39,15 +39,6 @@ enum BindAction
     BA_INSPECT
 };
 
-enum BindProto
-{
-    BP_ANY,
-    BP_IP,
-    BP_ICMP,
-    BP_TCP,
-    BP_UDP
-};
-
 struct Binding
 {
     // when
@@ -55,7 +46,7 @@ struct Binding
     std::string when_svc;
     VlanList vlans;
     std::string nets;
-    BindProto proto;
+    unsigned protos;
     PortList ports;
     BindRole role;
 
index cab5004329043df8ebab9189379faf544b890bd4..d3a1edb45dba0363aa62899f04c3db635b44fa38 100644 (file)
@@ -202,6 +202,7 @@ static TokenType get_token(
                 s += c;
                 state = 6;
             }
+            break;
         case 8:
             if ( c == '\n' )
             {