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

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