doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

Blame SOURCES/0258-lib-don-t-expect-kernel-s-version-2.6.-or-3.patch

baab13
From 333f0a462446edf67253a38ee1c194a4a44b411a Mon Sep 17 00:00:00 2001
baab13
From: Jakub Filak <jfilak@redhat.com>
baab13
Date: Mon, 30 Mar 2015 15:30:32 +0200
baab13
Subject: [PATCH] lib: don't expect kernel's version '2.6.*' or '3.*.*'
baab13
baab13
The function parsing kernel's version was expecting one of the strings
baab13
mentioned in Summary. Unfortunately, none of them appears in oopses for
baab13
kernel-4.*.*
baab13
baab13
I am not sure why the previous version didn't search for 'kernel-'
baab13
string, but I hope the previous authors know the reason. I can only
baab13
guess that 'kernel-' string is not always present, so I must not use it
baab13
in this commit. Hence, this commit switches to search by a regular
baab13
expression where I want to match a version string "\d.\d.\d" with
baab13
expectation of a release string in form of "-[^ )]+".
baab13
baab13
Resolves #1378469
baab13
baab13
Signed-off-by: Jakub Filak <jfilak@redhat.com>
baab13
---
baab13
 src/lib/kernel.c | 44 ++++++++++++++++++++++++++++++++++----------
baab13
 1 file changed, 34 insertions(+), 10 deletions(-)
baab13
baab13
diff --git a/src/lib/kernel.c b/src/lib/kernel.c
baab13
index 799463d..4e27d05 100644
baab13
--- a/src/lib/kernel.c
baab13
+++ b/src/lib/kernel.c
baab13
@@ -19,6 +19,8 @@
baab13
 #include <satyr/stacktrace.h>
baab13
 #include <satyr/thread.h>
baab13
 
baab13
+#include <regex.h>
baab13
+
baab13
 #define _GNU_SOURCE 1 /* for strcasestr */
baab13
 #include "libabrt.h"
baab13
 
baab13
@@ -532,19 +534,41 @@ char *koops_extract_version(const char *linepointer)
baab13
      || strstr(linepointer, "REGS")
baab13
      || strstr(linepointer, "EFLAGS")
baab13
     ) {
baab13
-        char* start;
baab13
-        char* end;
baab13
+        const char *regexp = "([0-9]+\\.[0-9]+\\.[0-9]+-[^ \\)]+)[ \\)]";
baab13
+        regex_t re;
baab13
+        int r = regcomp(&re, regexp, REG_EXTENDED);
baab13
+        if (r != 0)
baab13
+        {
baab13
+            char buf[LINE_MAX];
baab13
+            regerror(r, &re, buf, sizeof(buf));
baab13
+            error_msg("BUG: invalid kernel version regexp: %s", buf);
baab13
+            return NULL;
baab13
+        }
baab13
 
baab13
-        start = strstr(linepointer, "2.6.");
baab13
-        if (!start)
baab13
-            start = strstr(linepointer, "3.");
baab13
-        if (start)
baab13
+        regmatch_t matchptr[2];
baab13
+        r = regexec(&re, linepointer, 2, matchptr, 0);
baab13
+        if (r != 0)
baab13
         {
baab13
-            end = strchr(start, ')');
baab13
-            if (!end)
baab13
-                end = strchrnul(start, ' ');
baab13
-            return xstrndup(start, end-start);
baab13
+            if (r != REG_NOMATCH)
baab13
+            {
baab13
+                char buf[LINE_MAX];
baab13
+                regerror(r, &re, buf, sizeof(buf));
baab13
+                error_msg("BUG: kernel version regexp failed: %s", buf);
baab13
+            }
baab13
+            else
baab13
+            {
baab13
+                log_debug("A kernel version candidate line didn't match kernel oops regexp:");
baab13
+                log_debug("\t'%s'", linepointer);
baab13
+            }
baab13
+
baab13
+            regfree(&re);
baab13
+            return NULL;
baab13
         }
baab13
+
baab13
+        char *ret = xstrndup(linepointer + matchptr[1].rm_so, matchptr[1].rm_eo - matchptr[1].rm_so);
baab13
+
baab13
+        regfree(&re);
baab13
+        return ret;
baab13
     }
baab13
 
baab13
     return NULL;
baab13
-- 
baab13
1.8.3.1
baab13