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

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