]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3402: Handle optional quotes
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 10 May 2022 15:12:29 +0000 (15:12 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 10 May 2022 15:12:29 +0000 (15:12 +0000)
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

src/framework/value.h
src/ips_options/ips_file_type.cc
src/ips_options/ips_luajit.cc
src/ips_options/ips_sd_pattern.cc
src/service_inspectors/dce_rpc/ips_dce_opnum.cc

index 5a5be81ce1eb23d73815acab2e3ab6e724b4a888..39107803dce41f2a8f0f5060a63e2a1c65906a7c 100644 (file)
@@ -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;
 
index 856b135411237a651ae4dcc9937e116d3e5add8d..fdcc69ae9d13e9942685372cfe0832ede303221e 100644 (file)
@@ -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);
index 7cdfef35da649ddd1f4f1f9f643a7db0fb79cb21..e1eb583acc87c7846ff66efe5b57d47f55a870a1 100644 (file)
@@ -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;
 }
 
index c44c4e5434a83d83944fdcf5ab8f89500b4eb6af..82a2602b767a2818aa35e2c6cb5af0f7c2f4c664 100644 (file)
@@ -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();
 
index d10fc32d2a0ee46c06285b480d18111bceed7776..30203819bab46de596f129716f8bf6baa9b9645d 100644 (file)
@@ -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);