From: Russ Combs Date: Tue, 26 Aug 2014 17:54:09 +0000 (-0400) Subject: more FIXITs X-Git-Tag: 3.0.0-233~1419^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cd367627f0c433dd889e4482ddc317d50334e23;p=thirdparty%2Fsnort3.git more FIXITs --- diff --git a/src/ips_options/ips_pcre.cc b/src/ips_options/ips_pcre.cc index c060dfb10..817a7970f 100644 --- a/src/ips_options/ips_pcre.cc +++ b/src/ips_options/ips_pcre.cc @@ -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); } diff --git a/src/network_inspectors/binder/bind_module.cc b/src/network_inspectors/binder/bind_module.cc index f581db39f..1edb13bb8 100644 --- a/src/network_inspectors/binder/bind_module.cc +++ b/src/network_inspectors/binder/bind_module.cc @@ -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); diff --git a/src/network_inspectors/binder/binder.cc b/src/network_inspectors/binder/binder.cc index c0d204869..8744f7802 100644 --- a/src/network_inspectors/binder/binder.cc +++ b/src/network_inspectors/binder/binder.cc @@ -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) ) diff --git a/src/network_inspectors/binder/binder.h b/src/network_inspectors/binder/binder.h index 7e91d7b6a..ecb076755 100644 --- a/src/network_inspectors/binder/binder.h +++ b/src/network_inspectors/binder/binder.h @@ -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; diff --git a/src/parser/parse_stream.cc b/src/parser/parse_stream.cc index cab500432..d3a1edb45 100644 --- a/src/parser/parse_stream.cc +++ b/src/parser/parse_stream.cc @@ -202,6 +202,7 @@ static TokenType get_token( s += c; state = 6; } + break; case 8: if ( c == '\n' ) {