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

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