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