Blame SOURCES/0259-koops-do-not-assume-version-has-3-levels.patch

a60cd7
From adb5eabda368cdd05e9ed02cf91ce5e02bc26e0b Mon Sep 17 00:00:00 2001
a60cd7
From: Jakub Filak <jfilak@redhat.com>
a60cd7
Date: Wed, 25 May 2016 13:35:28 +0200
a60cd7
Subject: [PATCH] koops: do not assume version has 3 levels
a60cd7
a60cd7
Correct commit 9023d77ad5539433146b59e5ac80e3cefcb20cf7
a60cd7
a60cd7
Some ancient kernel versions have 4 levels. This commit allows version
a60cd7
string to have any level equal or greater than 3. The first 3 levels
a60cd7
must be numbers and the rest can be almost anything - it just must
a60cd7
follow the logical structure of levels (i.e. dot something dot
a60cd7
something) - this should allow a git hash in the version string.
a60cd7
a60cd7
In order to eliminate possible false positives introduced by the
a60cd7
flexibility of version levels the commit adds checks for
a60cd7
the prefixes ' ', '(' or 'kernel-' and the suffix ' #' or ') #'.
a60cd7
a60cd7
Resolves #1378469
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
---
a60cd7
 src/lib/kernel.c | 15 +++++++++++----
a60cd7
 1 file changed, 11 insertions(+), 4 deletions(-)
a60cd7
a60cd7
diff --git a/src/lib/kernel.c b/src/lib/kernel.c
a60cd7
index 4e27d05..1a9d327 100644
a60cd7
--- a/src/lib/kernel.c
a60cd7
+++ b/src/lib/kernel.c
a60cd7
@@ -534,7 +534,10 @@ char *koops_extract_version(const char *linepointer)
a60cd7
      || strstr(linepointer, "REGS")
a60cd7
      || strstr(linepointer, "EFLAGS")
a60cd7
     ) {
a60cd7
-        const char *regexp = "([0-9]+\\.[0-9]+\\.[0-9]+-[^ \\)]+)[ \\)]";
a60cd7
+        /* "(4.7.0-2.x86_64.fc25) #"    */
a60cd7
+        /* " 4.7.0-2.x86_64.fc25 #"     */
a60cd7
+        /* " 2.6.3.4.5-2.x86_64.fc22 #" */
a60cd7
+        const char *regexp = "([ \\(]|kernel-)([0-9]+\\.[0-9]+\\.[0-9]+(\\.[^.-]+)*-[^ \\)]+)\\)? #";
a60cd7
         regex_t re;
a60cd7
         int r = regcomp(&re, regexp, REG_EXTENDED);
a60cd7
         if (r != 0)
a60cd7
@@ -545,8 +548,8 @@ char *koops_extract_version(const char *linepointer)
a60cd7
             return NULL;
a60cd7
         }
a60cd7
 
a60cd7
-        regmatch_t matchptr[2];
a60cd7
-        r = regexec(&re, linepointer, 2, matchptr, 0);
a60cd7
+        regmatch_t matchptr[3];
a60cd7
+        r = regexec(&re, linepointer, sizeof(matchptr)/sizeof(matchptr[0]), matchptr, 0);
a60cd7
         if (r != 0)
a60cd7
         {
a60cd7
             if (r != REG_NOMATCH)
a60cd7
@@ -565,7 +568,11 @@ char *koops_extract_version(const char *linepointer)
a60cd7
             return NULL;
a60cd7
         }
a60cd7
 
a60cd7
-        char *ret = xstrndup(linepointer + matchptr[1].rm_so, matchptr[1].rm_eo - matchptr[1].rm_so);
a60cd7
+        /* 0: entire string */
a60cd7
+        /* 1: version prefix */
a60cd7
+        /* 2: version string */
a60cd7
+        const regmatch_t *const ver = matchptr + 2;
a60cd7
+        char *ret = xstrndup(linepointer + ver->rm_so, ver->rm_eo - ver->rm_so);
a60cd7
 
a60cd7
         regfree(&re);
a60cd7
         return ret;
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7