]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #105 in SNORT/snort3 from nhttp24 to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Thu, 29 Oct 2015 16:33:57 +0000 (12:33 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Thu, 29 Oct 2015 16:33:57 +0000 (12:33 -0400)
Squashed commit of the following:

commit 8540ae11d8ed7b88c5a01d4fe9a2604232475160
Author: Tom Peters <thopeter@cisco.com>
Date:   Thu Oct 29 12:27:46 2015 -0400

    remaining test code inside REG_TEST

23 files changed:
src/service_inspectors/nhttp_inspect/nhttp_enum.h
src/service_inspectors/nhttp_inspect/nhttp_field.cc
src/service_inspectors/nhttp_inspect/nhttp_field.h
src/service_inspectors/nhttp_inspect/nhttp_msg_body_chunk.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_body_chunk.h
src/service_inspectors/nhttp_inspect/nhttp_msg_body_cl.cc
src/service_inspectors/nhttp_inspect/nhttp_msg_body_cl.h
src/service_inspectors/nhttp_inspect/nhttp_msg_head_shared.cc
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_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_test_input.cc
src/service_inspectors/nhttp_inspect/nhttp_test_input.h
src/service_inspectors/nhttp_inspect/nhttp_test_manager.cc
src/service_inspectors/nhttp_inspect/nhttp_test_manager.h

index e05337b88828419fdd01a45c092323e949fc4e6e..4496f90e24761b396d15804d1968d56d4b0d738e 100644 (file)
@@ -28,7 +28,8 @@ static const int MAX_OCTETS = 65535;
 static const int DATA_BLOCK_SIZE = 16384;
 static const int FINAL_BLOCK_SIZE = 24576;
 static const int GZIP_BLOCK_SIZE = 2048;
-static const int FINAL_GZIP_BLOCK_SIZE = 2304;
+static const int FINAL_GZIP_BLOCK_SIZE = 2304; // compromise value, too big causes gzip overruns
+                                               // too small leaves too many little end sections
 static const uint32_t NHTTP_GID = 219;
 static const int GZIP_WINDOWBITS = 31;
 static const int DEFLATE_WINDOWBITS = 15;
index d9cd5bd024ac9eb8c276edffdccad9ac545ecc56..cdc9bab5005166448a4ef0c5384c51f3ba61da38 100644 (file)
@@ -30,6 +30,7 @@ using namespace NHttpEnums;
 
 const Field Field::FIELD_NULL { STAT_NOSOURCE };
 
+#ifdef REG_TEST
 void Field::print(FILE* output, const char* name) const
 {
     if ((length == STAT_NOTPRESENT) || (length == STAT_NOTCOMPUTE) || (length == STAT_NOSOURCE))
@@ -62,4 +63,5 @@ void Field::print(FILE* output, const char* name) const
     }
     fprintf(output, "\n");
 }
+#endif
 
index c18d24dc53a646541487a4acaccef2cc4916f300..86650c6ef40216307ff270233c9ae5c90017c1bb 100644 (file)
@@ -40,7 +40,10 @@ 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;
+
+#ifdef REG_TEST
     void print(FILE* output, const char* name) const;
+#endif
 };
 
 #endif
index 6cd7ad7fe3c9b1137139a02883bbe81948d9a2fb..c3e5293f4b7a680556bfaf3014b24fde54faf885 100644 (file)
 
 using namespace NHttpEnums;
 
-void NHttpMsgBodyChunk::print_section(FILE* output)
-{
-    NHttpMsgSection::print_message_title(output, "chunked body");
-    fprintf(output, "Cumulative octets %" PRIi64 "\n", body_octets);
-    detect_data.print(output, "Detect data");
-    NHttpMsgSection::print_message_wrapup(output);
-}
-
 void NHttpMsgBodyChunk::update_flow()
 {
     // Cutter deleted when zero-length chunk received
@@ -59,3 +51,13 @@ void NHttpMsgBodyChunk::update_flow()
     session_data->section_type[source_id] = SEC__NOTCOMPUTE;
 }
 
+#ifdef REG_TEST
+void NHttpMsgBodyChunk::print_section(FILE* output)
+{
+    NHttpMsgSection::print_message_title(output, "chunked body");
+    fprintf(output, "Cumulative octets %" PRIi64 "\n", body_octets);
+    detect_data.print(output, "Detect data");
+    NHttpMsgSection::print_message_wrapup(output);
+}
+#endif
+
index 6acfd157e9a40c80371d10a35587715b8dbafd00..d72098e154880497a99b286e28653d25a667e03c 100644 (file)
@@ -32,8 +32,11 @@ public:
     NHttpMsgBodyChunk(const uint8_t* buffer, const uint16_t buf_size, NHttpFlowData* session_data_,
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_, const NHttpParaList* params_)
         : NHttpMsgBody(buffer, buf_size, session_data_, source_id_, buf_owner, flow_, params_) {}
-    void print_section(FILE* output) override;
     void update_flow() override;
+
+#ifdef REG_TEST
+    void print_section(FILE* output) override;
+#endif
 };
 
 #endif
index 9a46be1f2629192fec83d0bd0b2e6bcf1ab6ef76..434aaf1777dc27d4065deb330cf7bb138d7ba71a 100644 (file)
 
 using namespace NHttpEnums;
 
-void NHttpMsgBodyCl::print_section(FILE* output)
-{
-    NHttpMsgSection::print_message_title(output, "Content-Length body");
-    fprintf(output, "Content-Length %" PRIi64 ", octets seen %" PRIi64 "\n", data_length,
-        body_octets);
-    detect_data.print(output, "Detect data");
-    NHttpMsgSection::print_message_wrapup(output);
-}
-
 void NHttpMsgBodyCl::update_flow()
 {
     if (session_data->cutter[source_id] != nullptr)
@@ -61,3 +52,14 @@ void NHttpMsgBodyCl::update_flow()
     session_data->section_type[source_id] = SEC__NOTCOMPUTE;
 }
 
+#ifdef REG_TEST
+void NHttpMsgBodyCl::print_section(FILE* output)
+{
+    NHttpMsgSection::print_message_title(output, "Content-Length body");
+    fprintf(output, "Content-Length %" PRIi64 ", octets seen %" PRIi64 "\n", data_length,
+        body_octets);
+    detect_data.print(output, "Detect data");
+    NHttpMsgSection::print_message_wrapup(output);
+}
+#endif
+
index 1731cf973504b688b65a3a605c04b7aba5e1875a..25f7d9b13cdd10beb6ceedbdd0da617484f9de3f 100644 (file)
@@ -35,9 +35,12 @@ public:
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_, const NHttpParaList* params_)
         : NHttpMsgBody(buffer, buf_size, session_data_, source_id_, buf_owner, flow_, params_),
         data_length(session_data->data_length[source_id]) {}
-    void print_section(FILE* output) override;
     void update_flow() override;
 
+#ifdef REG_TEST
+    void print_section(FILE* output) override;
+#endif
+
 protected:
     int64_t data_length;
 };
index c433f177955d47edfa84228e1ae5bd41bd573336..cf8c7463bed01efde711d1bb733a038f0510a6d6 100644 (file)
@@ -227,6 +227,7 @@ const Field& NHttpMsgHeadShared::get_header_value_norm(HeaderId header_id)
     return node->norm;
 }
 
+#ifdef REG_TEST
 void NHttpMsgHeadShared::print_headers(FILE* output)
 {
     char title_buf[100];
@@ -246,4 +247,5 @@ void NHttpMsgHeadShared::print_headers(FILE* output)
         }
     }
 }
+#endif
 
index 3f6e96ff820e40a92ae430eb2da4218bf259d3c7..5a74afaf5c695f0bda09c46bbcc7244581ada312 100644 (file)
@@ -74,8 +74,6 @@ protected:
     void parse_header_lines();
     void derive_header_name_id(int index);
 
-    void print_headers(FILE* output);
-
     // All of these are indexed by the relative position of the header field in the message
     static const int MAX_HEADERS = 200;  // I'm an arbitrary number. FIXIT-L
     static const int MAX_HEADER_LENGTH = 4096; // Based on max cookie size of some browsers
@@ -85,6 +83,10 @@ protected:
     NHttpEnums::HeaderId* header_name_id = nullptr;
     Field* header_value = nullptr;
 
+#ifdef REG_TEST
+    void print_headers(FILE* output);
+#endif
+
 private:
     static const int MAX = NHttpEnums::HEAD__MAX_VALUE;
     std::bitset<MAX> headers_present = 0;
index f5ede1f7f888e83e4628ca5fcbdd1d821dc65f3d..f1e575378c88dff53515fefa63c1611c34e79ce0 100644 (file)
@@ -39,13 +39,6 @@ NHttpMsgHeader::NHttpMsgHeader(const uint8_t* buffer, const uint16_t buf_size,
     transaction->set_header(this, source_id);
 }
 
-void NHttpMsgHeader::print_section(FILE* output)
-{
-    NHttpMsgSection::print_message_title(output, "header");
-    NHttpMsgHeadShared::print_headers(output);
-    NHttpMsgSection::print_message_wrapup(output);
-}
-
 void NHttpMsgHeader::update_flow()
 {
     session_data->section_type[source_id] = SEC__NOTCOMPUTE;
@@ -198,3 +191,12 @@ void NHttpMsgHeader::setup_decompression()
     }
 }
 
+#ifdef REG_TEST
+void NHttpMsgHeader::print_section(FILE* output)
+{
+    NHttpMsgSection::print_message_title(output, "header");
+    NHttpMsgHeadShared::print_headers(output);
+    NHttpMsgSection::print_message_wrapup(output);
+}
+#endif
+
index f7ac295b7effbca8862098c0831fe4927b452f38..c559d044673426eb4b9af6ceeec92eefcb531c03 100644 (file)
@@ -35,7 +35,6 @@ public:
     NHttpMsgHeader(const uint8_t* buffer, const uint16_t buf_size, NHttpFlowData* session_data_,
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_,
         const NHttpParaList* params_);
-    void print_section(FILE* output) override;
     void update_flow() override;
 private:
     // Dummy configurations to support MIME processing
@@ -45,6 +44,10 @@ private:
     void prepare_body();
     void setup_file_processing();
     void setup_decompression();
+
+#ifdef REG_TEST
+    void print_section(FILE* output) override;
+#endif
 };
 
 #endif
index 2f58975c9e28572cbf89f84113c147e37950a2f5..769939ed2512eef564f9925bc44da065d5554e45 100644 (file)
@@ -145,6 +145,27 @@ void NHttpMsgRequest::gen_events()
         events.create_event(EVENT_UNKNOWN_METHOD);
 }
 
+void NHttpMsgRequest::update_flow()
+{
+    // The following logic to determine body type is by no means the last word on this topic.
+    if (infractions & INF_BAD_REQ_LINE)
+    {
+        session_data->type_expected[source_id] = SEC_ABORT;
+        session_data->half_reset(source_id);
+    }
+    else
+    {
+        session_data->type_expected[source_id] = SEC_HEADER;
+        session_data->version_id[source_id] = version_id;
+        session_data->method_id = method_id;
+        session_data->infractions[source_id].reset();
+        session_data->events[source_id].reset();
+    }
+    session_data->section_type[source_id] = SEC__NOTCOMPUTE;
+}
+
+#ifdef REG_TEST
+
 void NHttpMsgRequest::print_section(FILE* output)
 {
     NHttpMsgSection::print_message_title(output, "request line");
@@ -174,22 +195,5 @@ void NHttpMsgRequest::print_section(FILE* output)
     NHttpMsgSection::print_message_wrapup(output);
 }
 
-void NHttpMsgRequest::update_flow()
-{
-    // The following logic to determine body type is by no means the last word on this topic.
-    if (infractions & INF_BAD_REQ_LINE)
-    {
-        session_data->type_expected[source_id] = SEC_ABORT;
-        session_data->half_reset(source_id);
-    }
-    else
-    {
-        session_data->type_expected[source_id] = SEC_HEADER;
-        session_data->version_id[source_id] = version_id;
-        session_data->method_id = method_id;
-        session_data->infractions[source_id].reset();
-        session_data->events[source_id].reset();
-    }
-    session_data->section_type[source_id] = SEC__NOTCOMPUTE;
-}
+#endif
 
index 34244c0a004e27a5132a07601e38f3f6dd65106c..ccc310285e43019f1961130b4b56bc825549b31d 100644 (file)
@@ -37,13 +37,16 @@ public:
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_,
         const NHttpParaList* params_);
     ~NHttpMsgRequest() { delete uri; }
-    void print_section(FILE* output) override;
     void gen_events() override;
     void update_flow() override;
     const Field& get_method() { return method; }
     const Field& get_uri();
     const Field& get_uri_norm_legacy();
 
+#ifdef REG_TEST
+    void print_section(FILE* output) override;
+#endif
+
 private:
     static const StrCode method_list[];
 
index 972a87168385b63e4204ea185723073f062e145c..e71d4c26c969864aeadc854574bce426dfd094aa 100644 (file)
@@ -52,29 +52,6 @@ NHttpMsgSection::NHttpMsgSection(const uint8_t* buffer, const uint16_t buf_size,
     delete_msg_on_destruct(buf_owner)
 { }
 
-void NHttpMsgSection::print_message_title(FILE* output, const char* title) const
-{
-    fprintf(output, "HTTP message %s:\n", title);
-    msg_text.print(output, "Input");
-}
-
-void NHttpMsgSection::print_message_wrapup(FILE* output)
-{
-    fprintf(output, "Infractions: %016" PRIx64 " %016" PRIx64 ", Events: %016" PRIx64 " %016" PRIx64 ", TCP Close: %s\n",
-        infractions.get_raw2(), infractions.get_raw(), events.get_raw2(), events.get_raw(), tcp_close ? "True" : "False");
-    for (unsigned k=1; k < HTTP_BUFFER_MAX; k++)
-    {
-        get_legacy(k).print(output, http_buffer_name[k]);
-    }
-    if (g_file_data.len > 0)
-    {
-        Field(g_file_data.len, g_file_data.data).print(output, "file_data");
-    }
-    fprintf(output, "\n");
-    session_data->show(output);
-    fprintf(output, "\n");
-}
-
 void NHttpMsgSection::update_depth() const
 {
     const int64_t& depth = (session_data->file_depth_remaining[source_id] >=
@@ -165,3 +142,30 @@ const Field& NHttpMsgSection::get_legacy(unsigned buffer_id)
     }
 }
 
+#ifdef REG_TEST
+
+void NHttpMsgSection::print_message_title(FILE* output, const char* title) const
+{
+    fprintf(output, "HTTP message %s:\n", title);
+    msg_text.print(output, "Input");
+}
+
+void NHttpMsgSection::print_message_wrapup(FILE* output)
+{
+    fprintf(output, "Infractions: %016" PRIx64 " %016" PRIx64 ", Events: %016" PRIx64 " %016" PRIx64 ", TCP Close: %s\n",
+        infractions.get_raw2(), infractions.get_raw(), events.get_raw2(), events.get_raw(), tcp_close ? "True" : "False");
+    for (unsigned k=1; k < HTTP_BUFFER_MAX; k++)
+    {
+        get_legacy(k).print(output, http_buffer_name[k]);
+    }
+    if (g_file_data.len > 0)
+    {
+        Field(g_file_data.len, g_file_data.data).print(output, "file_data");
+    }
+    fprintf(output, "\n");
+    session_data->show(output);
+    fprintf(output, "\n");
+}
+
+#endif
+
index 8672e0dd38d27618422e07c71237718e54f86f5d..61ee7928117201288d2d127528c479a663cc6167 100644 (file)
@@ -52,19 +52,16 @@ public:
 
     NHttpEnums::MethodId get_method_id() const { return method_id; }
 
+#ifdef REG_TEST
     // Test tool prints all derived message parts
     virtual void print_section(FILE* output) = 0;
+#endif
 
 protected:
     NHttpMsgSection(const uint8_t* buffer, const uint16_t buf_size, NHttpFlowData* session_data_,
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_, const NHttpParaList*
         params_);
 
-    // Convenience methods
-    void print_message_title(FILE* output, const char* title) const;
-    void print_message_wrapup(FILE* output);
-    void update_depth() const;
-
     const Field msg_text;
 
     NHttpFlowData* const session_data;
@@ -81,6 +78,13 @@ protected:
     NHttpEnums::MethodId method_id;
     int32_t status_code_num;
 
+    // Convenience methods
+    void update_depth() const;
+#ifdef REG_TEST
+    void print_message_title(FILE* output, const char* title) const;
+    void print_message_wrapup(FILE* output);
+#endif
+
 private:
     const bool delete_msg_on_destruct;
 };
index b1b95d36549a034c5deefddceb4999b768fc6583..d147ec06f6f5f3067aeb9fef4f65db98bb8ed05b 100644 (file)
@@ -144,15 +144,6 @@ void NHttpMsgStatus::gen_events()
     }
 }
 
-void NHttpMsgStatus::print_section(FILE* output)
-{
-    NHttpMsgSection::print_message_title(output, "status line");
-    fprintf(output, "Version Id: %d\n", version_id);
-    fprintf(output, "Status Code Num: %d\n", status_code_num);
-    reason_phrase.print(output, "Reason Phrase");
-    NHttpMsgSection::print_message_wrapup(output);
-}
-
 void NHttpMsgStatus::update_flow()
 {
     // The following logic to determine body type is by no means the last word on this topic.
@@ -172,3 +163,14 @@ void NHttpMsgStatus::update_flow()
     session_data->section_type[source_id] = SEC__NOTCOMPUTE;
 }
 
+#ifdef REG_TEST
+void NHttpMsgStatus::print_section(FILE* output)
+{
+    NHttpMsgSection::print_message_title(output, "status line");
+    fprintf(output, "Version Id: %d\n", version_id);
+    fprintf(output, "Status Code Num: %d\n", status_code_num);
+    reason_phrase.print(output, "Reason Phrase");
+    NHttpMsgSection::print_message_wrapup(output);
+}
+#endif
+
index 71c8ef42c705b28758c7ce4ba0ff7eaa7d5c3c46..b1c24b34298ef813468bb6ce4b62192ca40d397b 100644 (file)
@@ -33,13 +33,16 @@ public:
     NHttpMsgStatus(const uint8_t* buffer, const uint16_t buf_size, NHttpFlowData* session_data_,
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_,
         const NHttpParaList* params_);
-    void print_section(FILE* output) override;
     void gen_events() override;
     void update_flow() override;
 
     const Field& get_status_code() { return status_code; }
     const Field& get_reason_phrase() { return reason_phrase; }
 
+#ifdef REG_TEST
+    void print_section(FILE* output) override;
+#endif
+
 private:
     void parse_start_line() override;
     void derive_status_code_num();
index 8ba4ed5c2bf0f332c572b8639bd9b068e04146b1..9f8517970b91de9714588439097ee81e3b124e0b 100644 (file)
@@ -36,13 +36,6 @@ NHttpMsgTrailer::NHttpMsgTrailer(const uint8_t* buffer, const uint16_t buf_size,
     transaction->set_trailer(this, source_id);
 }
 
-void NHttpMsgTrailer::print_section(FILE* output)
-{
-    NHttpMsgSection::print_message_title(output, "trailer");
-    NHttpMsgHeadShared::print_headers(output);
-    NHttpMsgSection::print_message_wrapup(output);
-}
-
 void NHttpMsgTrailer::update_flow()
 {
     session_data->type_expected[source_id] =
@@ -51,3 +44,12 @@ void NHttpMsgTrailer::update_flow()
     session_data->section_type[source_id] = SEC__NOTCOMPUTE;
 }
 
+#ifdef REG_TEST
+void NHttpMsgTrailer::print_section(FILE* output)
+{
+    NHttpMsgSection::print_message_title(output, "trailer");
+    NHttpMsgHeadShared::print_headers(output);
+    NHttpMsgSection::print_message_wrapup(output);
+}
+#endif
+
index ce9137da5ccbbde5089386baede0e5776433c244..71d26f4e734fff4ce2dc7d57079892129e5a2415 100644 (file)
@@ -32,8 +32,11 @@ public:
     NHttpMsgTrailer(const uint8_t* buffer, const uint16_t buf_size, NHttpFlowData* session_data_,
         NHttpEnums::SourceId source_id_, bool buf_owner, Flow* flow_,
         const NHttpParaList* params_);
-    void print_section(FILE* output) override;
     void update_flow() override;
+
+#ifdef REG_TEST
+    void print_section(FILE* output) override;
+#endif
 };
 
 #endif
index 160fb661a3db09b4abbffa0fae918e07e6bf2a96..376c162feea308599914cc0bfc39d05a3a250560 100644 (file)
@@ -17,6 +17,8 @@
 //--------------------------------------------------------------------------
 // nhttp_test_input.cc author Tom Peters <thopeter@cisco.com>
 
+#ifdef REG_TEST
+
 #include <assert.h>
 #include <stdexcept>
 
@@ -403,4 +405,5 @@ void NHttpTestInput::reassemble(uint8_t** buffer, unsigned& length, SourceId sou
     just_flushed = true;
     flushed = false;
 }
+#endif
 
index ce9ff4d1a259a6643cc297821ddecb0b5a76005e..d8405e83dc78275ad1a6decbbf749818413fc68b 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef NHTTP_TEST_INPUT_H
 #define NHTTP_TEST_INPUT_H
 
+#ifdef REG_TEST
+
 #include <stdio.h>
 
 #include "nhttp_enum.h"
@@ -76,4 +78,5 @@ private:
 };
 
 #endif
+#endif
 
index 50b4624cee1ee27754af979e0406a382acb05802..8884cca11e3185ad797de21e78d2cb5f06efb5cb 100644 (file)
@@ -17,6 +17,8 @@
 //--------------------------------------------------------------------------
 // nhttp_test_manager.cc author Tom Peters <thopeter@cisco.com>
 
+#ifdef REG_TEST
+
 #include <stdexcept>
 
 #include "nhttp_test_manager.h"
@@ -54,3 +56,5 @@ void NHttpTestManager::activate_test_input()
     }
 }
 
+#endif
+
index 3019f974b219d1549185b0374dfafcc699104b7e..862adb0050984f177c51e49f37027608f3bc113f 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef NHTTP_TEST_MANAGER_H
 #define NHTTP_TEST_MANAGER_H
 
+#ifdef REG_TEST
+
 #include <sys/types.h>
 #include <stdio.h>
 
@@ -58,4 +60,5 @@ private:
 };
 
 #endif
+#endif