Merge in SNORT/snort3 from ~VHORBAN/snort3:handle_optional_quotes_graceflly to master
Squashed commit of the following:
commit
d3f04e4d0f9311610c09d83f6b3392bdf4d349bd
Author: Volodymyr Horban <vhorban@cisco.com>
Date: Fri Apr 22 18:08:13 2022 +0300
framework: add method to get unquoted string from configuration value
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;
tok.erase(0, 1);
if (tok.length() == 0)
- continue;
+ continue;
if ( tok[tok.length()-1] == '"' )
tok.erase(tok.length()-1, 1);
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;
}
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();
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);