]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #569 in SNORT/snort3 from linez to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Thu, 28 Jul 2016 16:37:13 +0000 (12:37 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Thu, 28 Jul 2016 16:37:13 +0000 (12:37 -0400)
Squashed commit of the following:

commit b15f074d2d03ba332b386eb7571a9bf2afdb4dfe
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Jul 28 12:08:37 2016 -0400

    refactor, comments

commit e877c882772db117208bd60286db5b4a4feb6eb9
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Jul 22 14:33:03 2016 -0400

    fix line number in rule parsing errors
    no line numbers for lua messages

doc/bugs.txt
src/log/messages.cc
src/parser/parse_conf.cc
src/parser/parser.cc
src/parser/parser.h

index ce7137ecfa0356a6c3942e17353d119737d1062c..f21c2f2d80641bccea3d10ee9fdb5abcc30ce25c 100644 (file)
@@ -26,7 +26,7 @@
 ==== Config
 
 * Parsing issue with IP lists.  can't parse rules with $EXTERNAL_NET
-  defined as below because or the space between ! and 10.
+  defined as below because of the space between ! and 10.
 
     HOME_NET = [[ 10.0.17.0/24 10.0.14.0/24 10.247.0.0/16 10.246.0.0/16 ]]
     EXTERNAL_NET = '! ' .. HOME_NET
 * --lua can only be used in addition to, not in place of, a -c config.
   Ideally, --lua could be used in lieu of -c.
 
-* Rule line numbers provided with syntax error messages are off by one. The first rule is
-  unnumbered, the second rule is one, etc. See nhttp_inspect/detection_buffers/bad_rules/expected
-  for an example.
-
 
 ==== Rules
 
index 36ad21bf2f9163856d2388580829955983e120e3..918b4cf1a38984635ff06f387fb0d809f5801929 100644 (file)
@@ -73,6 +73,18 @@ unsigned get_parse_warnings()
     return tmp;
 }
 
+static void log_message(const char* type, const char* msg)
+{
+    const char* file_name;
+    unsigned file_line;
+    get_parse_location(file_name, file_line);
+
+    if ( file_line )
+        LogMessage("%s: %s:%d %s\n", type, file_name, file_line, msg);
+    else
+        LogMessage("%s: %s\n", type, msg);
+}
+
 void ParseMessage(const char* format, ...)
 {
     char buf[STD_BUF+1];
@@ -83,16 +95,7 @@ void ParseMessage(const char* format, ...)
     va_end(ap);
 
     buf[STD_BUF] = '\0';
-
-    const char* file_name;
-    unsigned file_line;
-    get_parse_location(file_name, file_line);
-
-   // FIXIT-L use same format filename/linenum as ParseWarning ( %s(%d) vs $s:%d )
-   if ( file_name )
-        LogMessage("%s(%d) %s\n", file_name, file_line, buf);
-    else
-        LogMessage("%s\n", buf);
+    log_message("INFO", buf);
 }
 
 void ParseWarning(WarningGroup wg, const char* format, ...)
@@ -108,16 +111,7 @@ void ParseWarning(WarningGroup wg, const char* format, ...)
     va_end(ap);
 
     buf[STD_BUF] = '\0';
-
-    const char* file_name;
-    unsigned file_line;
-    get_parse_location(file_name, file_line);
-
-    // FIXIT-L Why `file_line` here and `file_name` in ParseMessage?
-    if ( file_line )
-        LogMessage("WARNING: %s:%d %s\n", file_name, file_line, buf);
-    else
-        LogMessage("WARNING: %s\n", buf);
+    log_message("WARNING", buf);
 
     parse_warnings++;
 }
@@ -132,15 +126,7 @@ void ParseError(const char* format, ...)
     va_end(ap);
 
     buf[STD_BUF] = '\0';
-
-    const char* file_name;
-    unsigned file_line;
-    get_parse_location(file_name, file_line);
-
-    if (file_line )
-        LogMessage("ERROR: %s:%d %s\n", file_name, file_line, buf);
-    else
-        LogMessage("ERROR: %s\n", buf);
+    log_message("ERROR", buf);
 
     parse_errors++;
 }
@@ -160,9 +146,8 @@ NORETURN void ParseAbort(const char* format, ...)
     unsigned file_line;
     get_parse_location(file_name, file_line);
 
-    // FIXIT-L Refer to ParseMessage above.
-    if ( file_name )
-        FatalError("%s(%u) %s\n", file_name, file_line, buf);
+    if ( file_line )
+        FatalError("%s:%u %s\n", file_name, file_line, buf);
     else
         FatalError("%s\n", buf);
 }
index e82facea9fa308130662baf4ccb9b6cda80d9ae4..df585b58826cbbc5e6dba4cae7f799a11ad1107d 100644 (file)
@@ -79,15 +79,6 @@ struct Location
 
 static std::stack<Location> files;
 
-const char* get_parse_file()
-{
-    if ( files.empty() )
-        return nullptr;
-
-    Location& loc = files.top();
-    return loc.file.c_str();
-}
-
 void get_parse_location(const char*& file, unsigned& line)
 {
     if ( files.empty() )
@@ -145,7 +136,7 @@ void parse_include(SnortConfig* sc, const char* arg)
         snprintf(fname, path_len, "%s%s", snort_conf_dir, arg);
     }
 
-    push_parse_location(fname, 0);
+    push_parse_location(fname);
     ParseConfigFile(sc, fname);
     pop_parse_location();
     snort_free((char*)fname);
index 366464d35a20d55be8ec7da501010a607a6c04e5..23db408033368c50defcc963445bd3ade16d4a61 100644 (file)
@@ -466,7 +466,7 @@ static void parse_file(SnortConfig* sc, Shell* sh)
     if ( !fname || !*fname )
         return;
 
-    push_parse_location(fname);
+    push_parse_location(fname, 0);
     sh->configure(sc);
     pop_parse_location();
 }
index 08c59cef4ec58895c351dbdd159abd9cd3aa416e..9a2fde712326ef094c7062b5c99966a04bf551c2 100644 (file)
 void parser_init();
 void parser_term();
 
-const char* get_parse_file();
+// line > 0 implies name is non-null
 void get_parse_location(const char*& name, unsigned& line);
-void push_parse_location(const char* name, unsigned line = 0);
+
+// use line = 0 for lua to suppress line numbers for errors or warnings
+void push_parse_location(const char* name, unsigned line = 1);
 
 void pop_parse_location();
 void inc_parse_position();