From: Tom Peters Date: Fri, 17 Oct 2014 21:23:17 +0000 (-0400) Subject: code review continues X-Git-Tag: 3.0.0-233~1357^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54f2518754fdf1cb3e7d27ba2edb2f2b5159acd7;p=thirdparty%2Fsnort3.git code review continues --- diff --git a/src/service_inspectors/nhttp_inspect/nhttp_api.cc b/src/service_inspectors/nhttp_inspect/nhttp_api.cc index a8f82d131..9f25d21ed 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_api.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_api.cc @@ -18,7 +18,6 @@ */ // nhttp_api.cc author Tom Peters -#include #include #include @@ -31,18 +30,13 @@ const char* NHttpApi::nhttp_my_name = "nhttp_inspect"; const char* NHttpApi::nhttp_help = "the new HTTP inspector!"; -void NHttpApi::nhttp_init() -{ - NHttpFlowData::init(); -} - Inspector* NHttpApi::nhttp_ctor(Module* mod) { - const NHttpModule* nhttpMod = (NHttpModule*) mod; - return new NHttpInspect(nhttpMod->get_test_input(), nhttpMod->get_test_output()); + const NHttpModule* const nhttp_mod = (NHttpModule*) mod; + return new NHttpInspect(nhttp_mod->get_test_input(), nhttp_mod->get_test_output()); } -static const char* buffers[] = +static const char* legacy_buffers[] = { "http_client_body", "http_cookie", @@ -70,7 +64,7 @@ const InspectApi NHttpApi::nhttp_api = }, IT_SERVICE, (uint16_t)PktType::TCP, - buffers, + legacy_buffers, "http", NHttpApi::nhttp_init, NHttpApi::nhttp_term, diff --git a/src/service_inspectors/nhttp_inspect/nhttp_api.h b/src/service_inspectors/nhttp_inspect/nhttp_api.h index 51b9e0b32..f34fe50a8 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_api.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_api.h @@ -36,7 +36,7 @@ private: static void nhttp_mod_dtor(Module* m) { delete m; }; static const char* nhttp_my_name; static const char* nhttp_help; - static void nhttp_init(); + static void nhttp_init() { NHttpFlowData::init(); }; static void nhttp_term() {}; static Inspector* nhttp_ctor(Module* mod); static void nhttp_dtor(Inspector* p) { delete p; }; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_field.cc b/src/service_inspectors/nhttp_inspect/nhttp_field.cc index 98b92cded..4c36318af 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_field.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_field.cc @@ -33,12 +33,12 @@ void Field::print(FILE *output, const char* name, bool int_vals) const { if ((length == STAT_NOTPRESENT) || (length == STAT_NOTCOMPUTE) || (length == STAT_NOSOURCE)) { return; } - int out_count = fprintf(output, "%s, length = %d, ", name, length); + const int out_count = fprintf(output, "%s, length = %d, ", name, length); if (length <= 0) { fprintf(output, "\n"); return; } - int32_t print_length = (length <= 1200) ? length : 1200; // Limit the amount of data printed + const int32_t print_length = (length <= 1200) ? length : 1200; // Limit the amount of data printed for (int k=0; k < print_length; k++) { if ((start[k] >= 0x20) && (start[k] <= 0x7E)) fprintf(output, "%c", (char)start[k]); else if (start[k] == 0xD) fprintf(output, "~"); @@ -52,26 +52,10 @@ void Field::print(FILE *output, const char* name, bool int_vals) const { if (int_vals && (print_length%8 == 0)) { fprintf(output, "\nInteger values ="); for (int j=0; j < print_length; j+=8) { + // FIXIT-L rewrite to eliminate doubtful cast fprintf(output, " %" PRIu64 , *((const uint64_t*)(start+j))); } } fprintf(output, "\n"); } - - - - - - - - - - - - - - - - - diff --git a/src/service_inspectors/nhttp_inspect/nhttp_field.h b/src/service_inspectors/nhttp_inspect/nhttp_field.h index b8173b085..d6d5917c8 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_field.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_field.h @@ -38,7 +38,7 @@ public: Field(int32_t length_, const uint8_t* start_) : length(length_), start(start_) {}; explicit Field(int32_t length_) : length(length_) { assert(length<=0); }; Field() = default; - void print(FILE *output, const char* name, bool int_vals = false) const; + void print(FILE* output, const char* name, bool int_vals = false) const; }; #endif diff --git a/src/service_inspectors/nhttp_inspect/nhttp_inspect.cc b/src/service_inspectors/nhttp_inspect/nhttp_inspect.cc index c40e5bd5e..c3059fa18 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_inspect.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_inspect.cc @@ -22,6 +22,8 @@ #include #include "stream/stream_api.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_msg_request.h" #include "nhttp_msg_status.h" diff --git a/src/service_inspectors/nhttp_inspect/nhttp_module.cc b/src/service_inspectors/nhttp_inspect/nhttp_module.cc index 146636da0..e6294bd4b 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_module.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_module.cc @@ -18,11 +18,9 @@ */ // nhttp_module.cc author Tom Peters -#include #include #include #include "snort.h" -#include "nhttp_enum.h" #include "nhttp_module.h" const Parameter NHttpModule::nhttp_params[] = @@ -46,7 +44,6 @@ bool NHttpModule::set(const char*, Value &val, SnortConfig*) { else { return false; } - return true; } diff --git a/src/service_inspectors/nhttp_inspect/nhttp_module.h b/src/service_inspectors/nhttp_inspect/nhttp_module.h index 06b605780..cca787df9 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_module.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_module.h @@ -22,6 +22,7 @@ #define NHTTP_MODULE_H #include "framework/module.h" +#include "nhttp_enum.h" #define NHTTP_HELP "new HTTP inspector" @@ -29,11 +30,11 @@ class NHttpModule : public Module { public: NHttpModule() : Module("nhttp_inspect", NHTTP_HELP, nhttp_params) {}; - bool begin(const char*, int, SnortConfig*); - bool end(const char*, int, SnortConfig*) { return true; }; - bool set(const char*, Value&, SnortConfig*); - unsigned get_gid() const { return NHttpEnums::NHTTP_GID; }; - const RuleMap* get_rules() const { return nhttp_events; }; + bool begin(const char*, int, SnortConfig*) override; + bool end(const char*, int, SnortConfig*) override { return true; }; + bool set(const char*, Value&, SnortConfig*) override; + unsigned get_gid() const override { return NHttpEnums::NHTTP_GID; }; + const RuleMap* get_rules() const override { return nhttp_events; }; bool get_test_input() const { return test_input; }; bool get_test_output() const { return test_output; }; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_body.cc b/src/service_inspectors/nhttp_inspect/nhttp_msg_body.cc index 00626e917..3b893f70d 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_body.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_body.cc @@ -24,6 +24,8 @@ #include #include "snort.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_msg_body.h" diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_body.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_body.h index 5e07a3702..b44772bcc 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_body.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_body.h @@ -32,11 +32,11 @@ class NHttpMsgBody : public NHttpMsgSection { public: NHttpMsgBody(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); - void analyze(); - void print_section(FILE *output); - void gen_events(); - void update_flow(); - void legacy_clients(); + void analyze() override; + void print_section(FILE *output) override; + void gen_events() override; + void update_flow() override; + void legacy_clients() override; protected: int64_t data_length; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_chunk.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_chunk.h index 28603f3a6..d38184e21 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_chunk.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_chunk.h @@ -31,9 +31,9 @@ class NHttpMsgChunk : public NHttpMsgBody { public: NHttpMsgChunk(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); - void print_section(FILE *output); - void gen_events(); - void update_flow(); + void print_section(FILE *output) override; + void gen_events() override; + void update_flow() override; }; #endif diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_head_shared.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_head_shared.h index 2ad9a32f1..85b2cdc22 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_head_shared.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_head_shared.h @@ -32,8 +32,8 @@ class NHttpMsgHeadShared: public NHttpMsgSection { public: - void analyze(); - void gen_events(); + void analyze() override; + void gen_events() override; int32_t get_num_headers() const { return num_headers; }; const Field& get_headers() const { return msg_text; }; @@ -48,7 +48,7 @@ protected: NHttpEnums::SourceId source_id_, bool buf_owner) : NHttpMsgSection(buffer, buf_size, session_data_, source_id_, buf_owner) {}; - // Header normalization strategies. There should be one of these for every different way we can process + // Header normalization strategies. There should be one defined for every different way we can process // a header field value. static const HeaderNormalizer NORMALIZER_NIL; static const HeaderNormalizer NORMALIZER_BASIC; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc b/src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc index 195f08dd9..21c9a62e7 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc @@ -24,6 +24,8 @@ #include #include "snort.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_msg_request.h" #include "nhttp_msg_header.h" diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_header.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_header.h index 97935067d..2294a6b16 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_header.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_header.h @@ -31,11 +31,11 @@ class NHttpMsgHeader: public NHttpMsgHeadShared { public: NHttpMsgHeader(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); - void print_section(FILE *output); - void gen_events(); - void update_flow(); - NHttpEnums::ProcessResult worth_detection(); - void legacy_clients(); + void print_section(FILE *output) override; + void gen_events() override; + void update_flow() override; + NHttpEnums::ProcessResult worth_detection() override; + void legacy_clients() override; }; #endif diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_request.cc b/src/service_inspectors/nhttp_inspect/nhttp_msg_request.cc index 0c58c6a71..d5bfa4d3a 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_request.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_request.cc @@ -24,6 +24,8 @@ #include #include "snort.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_msg_request.h" #include "nhttp_msg_header.h" diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_request.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_request.h index c61282081..a46533d91 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_request.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_request.h @@ -36,10 +36,10 @@ public: NHttpMsgRequest(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); ~NHttpMsgRequest() { delete uri; }; - void print_section(FILE *output); - void gen_events(); - void update_flow(); - void legacy_clients(); + void print_section(FILE *output) override; + void gen_events() override; + void update_flow() override; + void legacy_clients() override; const Field& get_method() { return method; }; const Field& get_uri(); const Field& get_uri_norm_legacy(); @@ -47,7 +47,7 @@ public: private: static const StrCode method_list[]; - void parse_start_line(); + void parse_start_line() override; void derive_method_id(); Field method; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_section.cc b/src/service_inspectors/nhttp_inspect/nhttp_msg_section.cc index 6318a63cd..e77764bdd 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_section.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_section.cc @@ -24,6 +24,8 @@ #include #include "snort.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_transaction.h" #include "nhttp_msg_section.h" @@ -34,7 +36,7 @@ using namespace NHttpEnums; NHttpMsgSection::NHttpMsgSection(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, - SourceId source_id_, bool buf_owner) : + SourceId source_id_, bool buf_owner) : msg_text(buf_size, buffer), session_data(session_data_), source_id(source_id_), @@ -66,13 +68,12 @@ void NHttpMsgSection::print_message_wrapup(FILE *output) const { } void NHttpMsgSection::create_event(EventSid sid) { - const uint32_t NHTTP_GID = 119; SnortEventqAdd(NHTTP_GID, (uint32_t)sid); events_generated |= (1 << (sid-1)); } void NHttpMsgSection::legacy_request() { - NHttpMsgRequest* request = transaction->get_request(); + NHttpMsgRequest* const request = transaction->get_request(); if (request == nullptr) return; if (request->get_method().length > 0) { SetHttpBuffer(HTTP_BUFFER_METHOD, request->get_method().start, (unsigned)request->get_method().length); @@ -86,7 +87,7 @@ void NHttpMsgSection::legacy_request() { } void NHttpMsgSection::legacy_status() { - NHttpMsgStatus* status = transaction->get_status(); + NHttpMsgStatus* const status = transaction->get_status(); if (status == nullptr) return; if (status->get_status_code().length > 0) { SetHttpBuffer(HTTP_BUFFER_STAT_CODE, status->get_status_code().start, (unsigned)status->get_status_code().length); @@ -97,7 +98,7 @@ void NHttpMsgSection::legacy_status() { } void NHttpMsgSection::legacy_header(bool use_trailer) { - NHttpMsgHeadShared* header = use_trailer ? + NHttpMsgHeadShared* const header = use_trailer ? (NHttpMsgHeadShared*)transaction->get_trailer(source_id) : (NHttpMsgHeadShared*)transaction->get_header(source_id); if (header == nullptr) return; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_section.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_section.h index 5e7a2ba42..28f0d17a0 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_section.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_section.h @@ -21,7 +21,6 @@ #ifndef NHTTP_MSG_SECTION_H #define NHTTP_MSG_SECTION_H -#include "detection/detection_util.h" #include "nhttp_scratch_pad.h" #include "nhttp_field.h" #include "nhttp_flow_data.h" @@ -47,12 +46,12 @@ public: NHttpEnums::MethodId get_method_id() const { return method_id; }; protected: - NHttpMsgSection(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, + NHttpMsgSection(const uint8_t* buffer, const uint16_t buf_size, NHttpFlowData* session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); // Convenience methods - void print_message_title(FILE *output, const char *title) const; - void print_message_wrapup(FILE *output) const; + void print_message_title(FILE* output, const char* title) const; + void print_message_wrapup(FILE* output) const; void create_event(NHttpEnums::EventSid sid); void legacy_request(); void legacy_status(); @@ -67,9 +66,6 @@ protected: const bool tcp_close; ScratchPad scratch_pad; - // This is where all the derived values, extracted message parts, and normalized values are. - // These are all scalars, buffer pointers, and buffer sizes. The actual buffers are in message buffer (raw pieces) - // or the scratch_pad (normalized pieces). uint64_t infractions; uint64_t events_generated = 0; NHttpEnums::VersionId version_id; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_start.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_start.h index 30d9b7518..5022627cc 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_start.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_start.h @@ -30,9 +30,9 @@ class NHttpMsgStart: public NHttpMsgSection { public: - void analyze(); - void gen_events(); - NHttpEnums::ProcessResult worth_detection(); + void analyze() override; + void gen_events() override; + NHttpEnums::ProcessResult worth_detection() override; protected: NHttpMsgStart(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_status.cc b/src/service_inspectors/nhttp_inspect/nhttp_msg_status.cc index 8e7de1117..62a1a5dfd 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_status.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_status.cc @@ -24,6 +24,8 @@ #include #include "snort.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_msg_status.h" #include "nhttp_msg_header.h" diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_status.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_status.h index cc7af4e8e..a4bf48f41 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_status.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_status.h @@ -32,17 +32,17 @@ class NHttpMsgStatus: public NHttpMsgStart { public: NHttpMsgStatus(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); - void analyze(); - void print_section(FILE *output); - void gen_events(); - void update_flow(); - void legacy_clients(); + void analyze() override; + void print_section(FILE *output) override; + void gen_events() override; + void update_flow() override; + void legacy_clients() override; const Field& get_status_code() { return status_code; }; const Field& get_reason_phrase() { return reason_phrase; }; private: - void parse_start_line(); + void parse_start_line() override; void derive_status_code_num(); Field status_code; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.cc b/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.cc index cbb6c8e38..5767271a1 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.cc @@ -24,6 +24,8 @@ #include #include "snort.h" +#include "detection/detection_util.h" + #include "nhttp_enum.h" #include "nhttp_msg_trailer.h" diff --git a/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.h b/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.h index 27f53d807..68235059e 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.h @@ -31,11 +31,11 @@ class NHttpMsgTrailer: public NHttpMsgHeadShared { public: NHttpMsgTrailer(const uint8_t *buffer, const uint16_t buf_size, NHttpFlowData *session_data_, NHttpEnums::SourceId source_id_, bool buf_owner); - void print_section(FILE *output); - void gen_events(); - void update_flow(); - NHttpEnums::ProcessResult worth_detection(); - void legacy_clients(); + void print_section(FILE *output) override; + void gen_events() override; + void update_flow() override; + NHttpEnums::ProcessResult worth_detection() override; + void legacy_clients() override; }; #endif diff --git a/src/service_inspectors/nhttp_inspect/nhttp_transaction.cc b/src/service_inspectors/nhttp_inspect/nhttp_transaction.cc index dd1c4ce70..f63fbf79e 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_transaction.cc +++ b/src/service_inspectors/nhttp_inspect/nhttp_transaction.cc @@ -59,7 +59,7 @@ NHttpTransaction* NHttpTransaction::attach_my_transaction(NHttpFlowData* session // Request section: put the old transaction in the pipeline and replace it with a new transaction. If the pipeline // overflows or underflows we stop using it and just delete the old transaction. if (session_data->section_type[source_id] == SEC_REQUEST) { - // When pipelining is not occurring the response should already have taken this tranaction and left nullptr. + // When pipelining is not occurring the response should already have taken this transaction and left nullptr. if (session_data->transaction[SRC_CLIENT] != nullptr) { if ((session_data->pipeline_overflow) || (session_data->pipeline_underflow)) { delete session_data->transaction[SRC_CLIENT]; diff --git a/src/service_inspectors/nhttp_inspect/nhttp_uri.h b/src/service_inspectors/nhttp_inspect/nhttp_uri.h index db473b7b3..7e0221ca8 100644 --- a/src/service_inspectors/nhttp_inspect/nhttp_uri.h +++ b/src/service_inspectors/nhttp_inspect/nhttp_uri.h @@ -66,7 +66,7 @@ public: private: static const StrCode scheme_list[]; - Field uri; + const Field uri; const NHttpEnums::MethodId method_id; Field scheme;