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

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