doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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