From 1ed0a60833f38025cf539891b60b4b0f8c720100 Mon Sep 17 00:00:00 2001 From: "Russ Combs (rucombs)" Date: Thu, 3 Dec 2015 12:33:56 -0500 Subject: [PATCH] Merge pull request #165 in SNORT/snort3 from crc/clang to master Squashed commit of the following: commit 32a6ac430b2ddda7782fb0d357c915900bcc2c93 Author: Russ Combs Date: Wed Dec 2 15:57:43 2015 -0500 review updates commit 3d1d209b73516f202695c49aabcea294bc9701ed Author: Russ Combs Date: Wed Dec 2 07:03:34 2015 -0500 fix clang related issues --- configure.ac | 10 +-- src/ips_options/ips_regex.cc | 3 + .../normalize/norm_module.cc | 63 +++++++++++-------- .../normalize/norm_module.h | 9 +++ 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/configure.ac b/configure.ac index bdd09eb68..6d9f93dd2 100644 --- a/configure.ac +++ b/configure.ac @@ -764,10 +764,12 @@ LIBS="$LIBS -lz" # pthreads (optional) #-------------------------------------------------------------------------- -AX_PTHREAD -LIBS="$PTHREAD_LIBS $LIBS" -CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" -LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS" +if test "x$CXX" = "xg++"; then + AX_PTHREAD + LIBS="$PTHREAD_LIBS $LIBS" + CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS" + LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS" +fi #-------------------------------------------------------------------------- # lzma (optional) diff --git a/src/ips_options/ips_regex.cc b/src/ips_options/ips_regex.cc index 59c62c307..c45b0117a 100644 --- a/src/ips_options/ips_regex.cc +++ b/src/ips_options/ips_regex.cc @@ -47,6 +47,9 @@ struct RegexConfig unsigned flags; bool relative; + RegexConfig() + { reset(); } + void reset() { re.clear(); diff --git a/src/network_inspectors/normalize/norm_module.cc b/src/network_inspectors/normalize/norm_module.cc index 372b50488..f42f9c30c 100644 --- a/src/network_inspectors/normalize/norm_module.cc +++ b/src/network_inspectors/normalize/norm_module.cc @@ -187,15 +187,29 @@ static const Parameter s_params[] = }; //------------------------------------------------------------------------- -// normalize parameters +// normalize module //------------------------------------------------------------------------- +// using string* instead of string because clang++ 5.1 +// vector::back() does not seem to return a reference +// +// FIXIT-L these are static since get_pegs() is const +// consider making that non-const +std::vector NormalizeModule::test_text; +std::vector NormalizeModule::test_pegs; + NormalizeModule::NormalizeModule() : Module(NORM_NAME, NORM_HELP, s_params) { memset(&config, 0, sizeof(config)); } +NormalizeModule::~NormalizeModule() +{ + for ( auto s : test_text ) + delete s; +} + ProfileStats* NormalizeModule::get_profile() const { return &norm_perf_stats; } @@ -360,38 +374,35 @@ bool NormalizeModule::end(const char* fqn, int, SnortConfig*) return true; } -static inline PegInfo createTestPeg(const PegInfo p) +void NormalizeModule::add_test_peg(const PegInfo& norm) const { - // using a static vector to ensure the char* referred to in the PegInfo - // are valid after this function returns - static vector test_pegs; - PegInfo test_peg; - - std::string test_name("test "); - test_name.append(p.name); - test_pegs.push_back(test_name); - test_peg.name = test_pegs.back().c_str(); - - std::string test_info("During inline mode, would have "); - test_info.append(p.help); - test_pegs.push_back(test_info); - test_peg.help = test_pegs.back().c_str(); - - return test_peg; + PegInfo test; + + std::string* test_name = new std::string("test "); + test_name->append(norm.name); + test_text.push_back(test_name); + test.name = test_text.back()->c_str(); + + std::string* test_info = new std::string("test "); + test_info->append(norm.help); + test_text.push_back(test_info); + test.help = test_text.back()->c_str(); + + test_pegs.push_back(test); } const PegInfo* NormalizeModule::get_pegs() const { - static vector pegs; - pegs.clear(); + if ( test_pegs.size() ) + return &test_pegs[0]; const PegInfo* p = Norm_GetPegs(); assert(p); while ( p->name ) { - pegs.push_back(*p); - pegs.push_back(createTestPeg(*p)); + test_pegs.push_back(*p); + add_test_peg(*p); p++; } @@ -400,13 +411,13 @@ const PegInfo* NormalizeModule::get_pegs() const while ( p->name ) { - pegs.push_back(*p); - pegs.push_back(createTestPeg(*p)); + test_pegs.push_back(*p); + add_test_peg(*p); p++; } - pegs.push_back(*p); - return &pegs[0]; + test_pegs.push_back(*p); + return &test_pegs[0]; } PegCount* NormalizeModule::get_counts() const diff --git a/src/network_inspectors/normalize/norm_module.h b/src/network_inspectors/normalize/norm_module.h index d036b6729..4daccd172 100644 --- a/src/network_inspectors/normalize/norm_module.h +++ b/src/network_inspectors/normalize/norm_module.h @@ -21,6 +21,9 @@ #ifndef NORM_MODULE_H #define NORM_MODULE_H +#include +#include + #include "framework/module.h" #include "norm.h" @@ -33,6 +36,7 @@ class NormalizeModule : public Module { public: NormalizeModule(); + ~NormalizeModule(); bool set(const char*, Value&, SnortConfig*) override; bool begin(const char*, int, SnortConfig*) override; @@ -49,7 +53,12 @@ private: bool set_ip4(const char*, Value&, SnortConfig*); bool set_tcp(const char*, Value&, SnortConfig*); + void add_test_peg(const PegInfo&) const; + NormalizerConfig config; + + static std::vector test_text; + static std::vector test_pegs; }; #endif -- 2.47.3