Blame SOURCES/0057-a-a-save-package-data-Use-regexps-to-match-interpret.patch

8d5775
From caf03304c98dc84086b2f4f60be4b41fc76f31e6 Mon Sep 17 00:00:00 2001
8d5775
From: Martin Kutlak <mkutlak@redhat.com>
8d5775
Date: Wed, 4 Mar 2020 16:41:28 +0100
8d5775
Subject: [PATCH] a-a-save-package-data: Use regexps to match interpreters
8d5775
8d5775
Instead of adding more and more interpreters to the list which
8d5775
gets outdated after a while, we can utilize regular expressions.
8d5775
8d5775
User will still have an option to set Interpreters in config file to
8d5775
match any other interpreters.
8d5775
8d5775
The regexes should cover interpreters:
8d5775
8d5775
Python:
8d5775
 * python
8d5775
 * python2
8d5775
 * python2.7
8d5775
 * python3
8d5775
 * python3.8
8d5775
 * platform-python
8d5775
 * platform-python3
8d5775
 * platform-python3.8
8d5775
8d5775
Perl:
8d5775
 * perl
8d5775
 * perl5.30.1
8d5775
8d5775
PHP:
8d5775
 * php
8d5775
 * php-cgi
8d5775
8d5775
R
8d5775
retrace.fedoraproject.org/faf/reports/2832480
8d5775
tcl
8d5775
retrace.fedoraproject.org/faf/reports/2555398
8d5775
8d5775
The regexes should cover interpreters:
8d5775
R:
8d5775
 * R
8d5775
8d5775
tcl:
8d5775
 * tclsh
8d5775
 * tclsh8.6
8d5775
8d5775
Tests require will-crash and perl-interpreter installed.
8d5775
8d5775
Resolves: rhbz#1798494
8d5775
8d5775
Signed-off-by: Martin Kutlak <mkutlak@redhat.com>
8d5775
---
8d5775
 src/daemon/abrt-action-save-package-data.c    | 39 ++++++++-
8d5775
 1 files change, 38 insertions(+), 1 deletions(-)
8d5775
8d5775
diff --git a/src/daemon/abrt-action-save-package-data.c b/src/daemon/abrt-action-save-package-data.c
8d5775
index 21b4c97d..6ced7971 100644
8d5775
--- a/src/daemon/abrt-action-save-package-data.c
8d5775
+++ b/src/daemon/abrt-action-save-package-data.c
8d5775
@@ -17,11 +17,47 @@
8d5775
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
8d5775
 */
8d5775
 #include <fnmatch.h>
8d5775
+#include <glib.h>
8d5775
 #include "libabrt.h"
8d5775
 #include "rpm.h"
8d5775
 
8d5775
 #define GPG_CONF "gpg_keys.conf"
8d5775
 
8d5775
+/**
8d5775
+    "python3.4, python3.5, python3.6, python3.7, perl, perl5.16.2"
8d5775
+  * The regexes should cover interpreters with basename:
8d5775
+  * Python:
8d5775
+  *   python
8d5775
+  *   python2
8d5775
+  *   python3
8d5775
+  *   python2.7
8d5775
+  *   python3.8
8d5775
+  *   platform-python
8d5775
+  *   platform-python3
8d5775
+  *   platform-python3.8
8d5775
+  *
8d5775
+  * Perl:
8d5775
+  *   perl
8d5775
+  *   perl5.30.1
8d5775
+  *
8d5775
+  * PHP:
8d5775
+  *   php
8d5775
+  *   php-cgi
8d5775
+  *
8d5775
+  * R:
8d5775
+  *   R
8d5775
+  *
8d5775
+  * tcl:
8d5775
+  *   tclsh
8d5775
+  *   tclsh8.6
8d5775
+  **/
8d5775
+#define DEFAULT_INTERPRETERS_REGEX \
8d5775
+    "^(perl ([[:digit:]][.][[:digit:]]+[.][[:digit:]])? |" \
8d5775
+    "php (-cgi)? |" \
8d5775
+    "(platform-)? python ([[:digit:]]([.][[:digit:]])?)? |" \
8d5775
+    "R |" \
8d5775
+    "tclsh ([[:digit:]][.][[:digit:]])?)$"
8d5775
+
8d5775
 static bool   settings_bOpenGPGCheck = false;
8d5775
 static GList *settings_setOpenGPGPublicKeys = NULL;
8d5775
 static GList *settings_setBlackListedPkgs = NULL;
8d5775
@@ -304,7 +340,8 @@ static int SavePackageDescriptionToDebugDump(const char *dump_dir_name, const ch
8d5775
     /* if basename is known interpreter, we want to blame the running script
8d5775
      * not the interpreter
8d5775
      */
8d5775
-    if (g_list_find_custom(settings_Interpreters, basename, (GCompareFunc)g_strcmp0))
8d5775
+    if (g_regex_match_simple(DEFAULT_INTERPRETERS_REGEX, basename, G_REGEX_EXTENDED, /*MatchFlags*/0) ||
8d5775
+        g_list_find_custom(settings_Interpreters, basename, (GCompareFunc)g_strcmp0))
8d5775
     {
8d5775
         struct pkg_envra *script_pkg = get_script_name(cmdline, &executable, chroot);
8d5775
         /* executable may have changed, check it again */
8d5775
-- 
8d5775
2.25.1
8d5775