]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
code review continues
authorTom Peters <thopeter@cisco.com>
Fri, 17 Oct 2014 21:23:17 +0000 (17:23 -0400)
committerTom Peters <thopeter@cisco.com>
Fri, 17 Oct 2014 21:23:17 +0000 (17:23 -0400)
24 files changed:
src/service_inspectors/nhttp_inspect/nhttp_api.cc
src/service_inspectors/nhttp_inspect/nhttp_api.h
src/service_inspectors/nhttp_inspect/nhttp_field.cc
src/service_inspectors/nhttp_inspect/nhttp_field.h
src/service_inspectors/nhttp_inspect/nhttp_inspect.cc
src/service_inspectors/nhttp_inspect/nhttp_module.cc
src/service_inspectors/nhttp_inspect/nhttp_module.h
src/service_inspectors/nhttp_inspect/nhttp_msg_body.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_body.h
src/service_inspectors/nhttp_inspect/nhttp_msg_chunk.h
src/service_inspectors/nhttp_inspect/nhttp_msg_head_shared.h
src/service_inspectors/nhttp_inspect/nhttp_msg_header.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_header.h
src/service_inspectors/nhttp_inspect/nhttp_msg_request.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_request.h
src/service_inspectors/nhttp_inspect/nhttp_msg_section.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_section.h
src/service_inspectors/nhttp_inspect/nhttp_msg_start.h
src/service_inspectors/nhttp_inspect/nhttp_msg_status.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_status.h
src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_trailer.h
src/service_inspectors/nhttp_inspect/nhttp_transaction.cc
src/service_inspectors/nhttp_inspect/nhttp_uri.h

index a8f82d131eb34caf1dc63669e2f2959c78823f9d..9f25d21ed910798b9badffcff011812b0dea9a13 100644 (file)
@@ -18,7 +18,6 @@
 */
 // nhttp_api.cc author Tom Peters <thopeter@cisco.com>
 
-#include <assert.h>
 #include <string.h>
 #include <sys/types.h>
 
 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,
index 51b9e0b323787da803196a25f50b186cd8c20658..f34fe50a8f18c6983714451a2e28a3e15d434681 100644 (file)
@@ -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; };
index 98b92cded5315df859ba9081220633463aa06315..4c36318aff72c09c5c5675d741d7a0673b7d3a61 100644 (file)
@@ -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");
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
index b8173b085e11648f7950e057117122ff56170ad4..d6d5917c8f5d35d8df09fec0c2f9ef356bf4d4cf 100644 (file)
@@ -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(FILEoutput, const char* name, bool int_vals = false) const;
 };
 
 #endif
index c40e5bd5ef69fbe040d00b07f04a4ab8c61bbd54..c3059fa18970ac602c724a5015abaf1c032fdfa9 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdio.h>
 
 #include "stream/stream_api.h"
+#include "detection/detection_util.h"
+
 #include "nhttp_enum.h"
 #include "nhttp_msg_request.h"
 #include "nhttp_msg_status.h"
index 146636da0802d055426d69bfc8c7525c31663f2f..e6294bd4b6ba2d3fa106f9373a7b09ff3c8cf06c 100644 (file)
 */
 // nhttp_module.cc author Tom Peters <thopeter@cisco.com>
 
-#include <assert.h>
 #include <string.h>
 #include <sys/types.h>
 #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;
 }
 
index 06b60578067c0e97d77e319230526eff24febd64..cca787df98ccfbb6d8fe56248c5f557d8e415581 100644 (file)
@@ -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; };
 
index 00626e917bb329c4adaefed8903da918381a4cfb..3b893f70dc582c09797ecc67233c461f52e5966f 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 
 #include "snort.h"
+#include "detection/detection_util.h"
+
 #include "nhttp_enum.h"
 #include "nhttp_msg_body.h"
 
index 5e07a3702e9b0efc63fbaf8bbcf11a8e15e65424..b44772bcce650236c3dd00e9ce2f90c6cdf03f8b 100644 (file)
@@ -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;
index 28603f3a67fa388890469a846c4eb52eb20e0e05..d38184e21b736e9c6bbbf374b811ca14cd773fc3 100644 (file)
@@ -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
index 2ad9a32f190cf11fc75b240fff7fa9797f26a3ae..85b2cdc22295843eff82c4debeb060c969b35074 100644 (file)
@@ -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;
index 195f08dd91b0ff89b249445437f88abcdd06daf8..21c9a62e7bfb8b0f5066a493f58003443ac6623c 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 
 #include "snort.h"
+#include "detection/detection_util.h"
+
 #include "nhttp_enum.h"
 #include "nhttp_msg_request.h"
 #include "nhttp_msg_header.h"
index 97935067d30a58591fb1b4665e91a839d3442dc8..2294a6b169d67217fa98f8152c45799f9b08776d 100644 (file)
@@ -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
index 0c58c6a71a197a5d93dd87eddfd196dbcb27da73..d5bfa4d3a61cc5e8bff9ec1a87445a171f82d513 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 
 #include "snort.h"
+#include "detection/detection_util.h"
+
 #include "nhttp_enum.h"
 #include "nhttp_msg_request.h"
 #include "nhttp_msg_header.h"
index c61282081048f7364004bf77c1e63dbba6b9c7bc..a46533d91307ca2015ed6e725097637ff3caa07e 100644 (file)
@@ -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;
index 6318a63cda9214fb9e36110e69f271ee84b24fbc..e77764bdda27528c1ac9688df1544a7fad30a354 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 
 #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;
index 5e7a2ba42027e160445d4e94e96eed6d50aca93b..28f0d17a0ac94c46362ad7e44bea7b6306779d1a 100644 (file)
@@ -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(FILEoutput) 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;
index 30d9b75185ce104218a7dd1f4a5844b1b1a5211e..5022627cc8acb8a99b12d58a0344d8de1dd98016 100644 (file)
@@ -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_,
index 8e7de11170dfc357cb9945467a5bc5dc418743fb..62a1a5dfdafd7063f2dffde63d2d40ed5f52d203 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 
 #include "snort.h"
+#include "detection/detection_util.h"
+
 #include "nhttp_enum.h"
 #include "nhttp_msg_status.h"
 #include "nhttp_msg_header.h"
index cc7af4e8e9e5f93ad472fa78be4e93c887a4120a..a4bf48f41558d99f98a964b9392365cea823f5e2 100644 (file)
@@ -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;
index cbb6c8e3869dd043616c9880430fd11adc06fa95..5767271a14e96f20dfbae3b3ad499161874604f1 100644 (file)
@@ -24,6 +24,8 @@
 #include <stdio.h>
 
 #include "snort.h"
+#include "detection/detection_util.h"
+
 #include "nhttp_enum.h"
 #include "nhttp_msg_trailer.h"
 
index 27f53d8079ef1c53c85212382a01ffccd5e5127d..68235059e770db003809d05389e7a9089e1ba4b6 100644 (file)
@@ -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
index dd1c4ce70755b85d10c987b8846cee6013ee424a..f63fbf79e91444fd588b00499950c585778faab4 100644 (file)
@@ -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];
index db473b7b321074eba8a9deac41aaa920ef491b54..7e0221ca817651fbc83d0ceaaca637e8fc11f4c1 100644 (file)
@@ -66,7 +66,7 @@ public:
 private:
     static const StrCode scheme_list[];
 
-    Field uri;
+    const Field uri;
     const NHttpEnums::MethodId method_id;
 
     Field scheme;