Blame SOURCES/0278-koops-add-suspicious-strings-blacklist.patch

06486d
From a2cdf73fa34cf196b08932841d107a82c5bc16e5 Mon Sep 17 00:00:00 2001
06486d
From: Matej Habrnal <mhabrnal@redhat.com>
06486d
Date: Mon, 14 Aug 2017 13:34:59 +0200
06486d
Subject: [PATCH] koops: add suspicious strings blacklist
06486d
06486d
Some strings were accidentally considered suspicious.
06486d
In this concrete case strings containing "DEBUG" substring.
06486d
Since "BUG" and "DEBUG" overlaps and "BUG" is
06486d
listed in suspicious string list, kernel DEBUG messages were
06486d
recognized as "BUG"s which are kernel oops-es.
06486d
06486d
Added "DEBUG" string into mentioned new blacklist.
06486d
06486d
Related to rhbz#1228344
06486d
06486d
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
06486d
---
06486d
 src/include/libabrt.h |  2 ++
06486d
 src/lib/kernel.c      | 60 ++++++++++++++++++++++++++++++++++-----------------
06486d
 2 files changed, 42 insertions(+), 20 deletions(-)
06486d
06486d
diff --git a/src/include/libabrt.h b/src/include/libabrt.h
06486d
index 2510a77..5346328 100644
06486d
--- a/src/include/libabrt.h
06486d
+++ b/src/include/libabrt.h
06486d
@@ -125,6 +125,8 @@ char *kernel_tainted_long(const char *tainted_short);
06486d
 int koops_hash_str(char hash_str[SHA1_RESULT_LEN*2 + 1], const char *oops_buf);
06486d
 #define koops_extract_oopses abrt_koops_extract_oopses
06486d
 void koops_extract_oopses(GList **oops_list, char *buffer, size_t buflen);
06486d
+#define koops_suspicious_strings_blacklist abrt_koops_suspicious_strings_blacklist
06486d
+GList *koops_suspicious_strings_blacklist(void);
06486d
 #define koops_print_suspicious_strings abrt_koops_print_suspicious_strings
06486d
 void koops_print_suspicious_strings(void);
06486d
 /**
06486d
diff --git a/src/lib/kernel.c b/src/lib/kernel.c
06486d
index 1a9d327..79e7424 100644
06486d
--- a/src/lib/kernel.c
06486d
+++ b/src/lib/kernel.c
06486d
@@ -158,11 +158,46 @@ static const char *const s_koops_suspicious_strings[] = {
06486d
     NULL
06486d
 };
06486d
 
06486d
+static const char *const s_koops_suspicious_strings_blacklist[] = {
06486d
+    /* "BUG:" and "DEBUG:" overlaps, we don't want to recognize DEBUG messages as BUG */
06486d
+    "DEBUG:",
06486d
+
06486d
+    /* Termination */
06486d
+    NULL
06486d
+};
06486d
+
06486d
+static bool suspicious_line(const char *line)
06486d
+{
06486d
+    const char *const *str = s_koops_suspicious_strings;
06486d
+    for ( ; *str; ++str)
06486d
+        if (strstr(line, *str))
06486d
+            break;
06486d
+
06486d
+    if (!*str)
06486d
+        return false;
06486d
+
06486d
+    str = s_koops_suspicious_strings_blacklist;
06486d
+    for ( ; *str; ++str)
06486d
+        if (strstr(line, *str))
06486d
+           break;
06486d
+
06486d
+    return !*str;
06486d
+}
06486d
+
06486d
 void koops_print_suspicious_strings(void)
06486d
 {
06486d
     koops_print_suspicious_strings_filtered(NULL);
06486d
 }
06486d
 
06486d
+GList *koops_suspicious_strings_blacklist(void)
06486d
+{
06486d
+    GList *strings = NULL;
06486d
+    for (const char *const *str = s_koops_suspicious_strings_blacklist; *str; ++str)
06486d
+        strings = g_list_prepend(strings, (gpointer)*str);
06486d
+
06486d
+    return strings;
06486d
+}
06486d
+
06486d
 static bool match_any(const regex_t **res, const char *str)
06486d
 {
06486d
     for (const regex_t **r = res; *r != NULL; ++r)
06486d
@@ -312,14 +347,8 @@ next_line:
06486d
         if (oopsstart < 0)
06486d
         {
06486d
             /* Find start-of-oops markers */
06486d
-            for (const char *const *str = s_koops_suspicious_strings; *str; ++str)
06486d
-            {
06486d
-                if (strstr(curline, *str))
06486d
-                {
06486d
-                    oopsstart = i;
06486d
-                    break;
06486d
-                }
06486d
-            }
06486d
+            if (suspicious_line(curline))
06486d
+                oopsstart = i;
06486d
 
06486d
             if (oopsstart >= 0)
06486d
             {
06486d
@@ -407,18 +436,9 @@ next_line:
06486d
             /* kernel end-of-oops marker (not including marker itself) */
06486d
             else if (strstr(curline, "---[ end trace"))
06486d
                 oopsend = i-1;
06486d
-            else
06486d
-            {
06486d
-                /* if a new oops starts, this one has ended */
06486d
-                for (const char *const *str = s_koops_suspicious_strings; *str; ++str)
06486d
-                {
06486d
-                    if (strstr(curline, *str))
06486d
-                    {
06486d
-                        oopsend = i-1;
06486d
-                        break;
06486d
-                    }
06486d
-                }
06486d
-            }
06486d
+            /* if a new oops starts, this one has ended */
06486d
+            else if (suspicious_line(curline))
06486d
+                oopsend = i-1;
06486d
 
06486d
             if (oopsend <= i)
06486d
             {
06486d
-- 
06486d
1.8.3.1
06486d