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

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