doczkal / rpms / abrt

Forked from rpms/abrt 4 years ago
Clone

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

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