From: Mike Stepanek (mstepane) Date: Tue, 10 May 2022 15:12:29 +0000 (+0000) Subject: Pull request #3402: Handle optional quotes X-Git-Tag: 3.1.30.0~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f45c45e5006569b38a114051104fab3544107bec;p=thirdparty%2Fsnort3.git Pull request #3402: Handle optional quotes Merge in SNORT/snort3 from ~VHORBAN/snort3:handle_optional_quotes_graceflly to master Squashed commit of the following: commit d3f04e4d0f9311610c09d83f6b3392bdf4d349bd Author: Volodymyr Horban Date: Fri Apr 22 18:08:13 2022 +0300 framework: add method to get unquoted string from configuration value --- diff --git a/src/framework/value.h b/src/framework/value.h index 5a5be81ce..39107803d 100644 --- a/src/framework/value.h +++ b/src/framework/value.h @@ -158,6 +158,22 @@ public: Parameter::Type get_param_type() const; std::string get_origin_string() const; + std::string get_unquoted_string() const + { + if ( str.length() < 2 ) + return str; + + std::string tmp = str; + + if ( tmp.front() == '"' and tmp.back() == '"' ) + { + tmp.erase(0, 1); + tmp.erase(tmp.size() - 1, 1); + } + + return tmp; + } + bool strtol(long&) const; bool strtol(long&, const std::string&) const; diff --git a/src/ips_options/ips_file_type.cc b/src/ips_options/ips_file_type.cc index 856b13541..fdcc69ae9 100644 --- a/src/ips_options/ips_file_type.cc +++ b/src/ips_options/ips_file_type.cc @@ -155,7 +155,7 @@ bool FileTypeModule::set(const char*, Value& v, SnortConfig* sc) tok.erase(0, 1); if (tok.length() == 0) - continue; + continue; if ( tok[tok.length()-1] == '"' ) tok.erase(tok.length()-1, 1); diff --git a/src/ips_options/ips_luajit.cc b/src/ips_options/ips_luajit.cc index 7cdfef35d..e1eb583ac 100644 --- a/src/ips_options/ips_luajit.cc +++ b/src/ips_options/ips_luajit.cc @@ -96,16 +96,9 @@ bool LuaJitModule::begin(const char*, int, SnortConfig*) bool LuaJitModule::set(const char*, Value& v, SnortConfig*) { - args = v.get_string(); - // if args not empty, it has to be a quoted string // so remove enclosing quotes - if ( args.size() > 1 ) - { - args.erase(0, 1); - args.erase(args.size()-1); - } - + args = v.get_unquoted_string(); return true; } diff --git a/src/ips_options/ips_sd_pattern.cc b/src/ips_options/ips_sd_pattern.cc index c44c4e543..82a2602b7 100644 --- a/src/ips_options/ips_sd_pattern.cc +++ b/src/ips_options/ips_sd_pattern.cc @@ -339,12 +339,7 @@ bool SdPatternModule::begin(const char*, int, SnortConfig*) bool SdPatternModule::set(const char*, Value& v, SnortConfig*) { if ( v.is("~pattern") ) - { - config.pii = v.get_string(); - // remove quotes - config.pii.erase(0, 1); - config.pii.erase(config.pii.length()-1, 1); - } + config.pii = v.get_unquoted_string(); else if ( v.is("threshold") ) config.threshold = v.get_uint32(); diff --git a/src/service_inspectors/dce_rpc/ips_dce_opnum.cc b/src/service_inspectors/dce_rpc/ips_dce_opnum.cc index d10fc32d2..30203819b 100644 --- a/src/service_inspectors/dce_rpc/ips_dce_opnum.cc +++ b/src/service_inspectors/dce_rpc/ips_dce_opnum.cc @@ -490,15 +490,7 @@ bool Dce2OpnumModule::begin(const char*, int, SnortConfig*) bool Dce2OpnumModule::set(const char*, Value& v, SnortConfig*) { assert(v.is("~")); - - std::string tok (v.get_string()); - - if ( tok[0] == '"' ) - tok.erase(0, 1); - - if ( tok[tok.length()-1] == '"' ) - tok.erase(tok.length()-1, 1); - + std::string tok = v.get_unquoted_string(); char* s = snort_strdup(tok.c_str()); DCE2_Ret status = DCE2_OpnumParse(s, &opnum); snort_free(s);