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

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