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

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