File do-not-crash-when-unexpected-cmd-output-at-listing-p.patch of Package salt.18653

From 6ded5ab0dd7fd3fcfa36290bb1d198642c56764a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Mon, 25 Jan 2021 12:15:59 +0000
Subject: [PATCH] Do not crash when unexpected cmd output at listing
 patches (bsc#1181290)

---
 salt/modules/yumpkg.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/salt/modules/yumpkg.py b/salt/modules/yumpkg.py
index deb17f5af8..722bbc0350 100644
--- a/salt/modules/yumpkg.py
+++ b/salt/modules/yumpkg.py
@@ -3217,9 +3217,16 @@ def _get_patches(installed_only=False):
         python_shell=False,
         env={"SALT_RUNNING": '1'}
     )
+    parsing_errors = False
+
     for line in salt.utils.itertools.split(ret, os.linesep):
-        inst, advisory_id, sev, pkg = re.match(r'([i|\s]) ([^\s]+) +([^\s]+) +([^\s]+)',
-                                               line).groups()
+        try:
+            inst, advisory_id, sev, pkg = re.match(r'([i|\s]) ([^\s]+) +([^\s]+) +([^\s]+)',
+                                                   line).groups()
+        except Exception:
+            parsing_errors = True
+            continue
+
         if advisory_id not in patches:
             patches[advisory_id] = {
                 'installed': True if inst == 'i' else False,
@@ -3230,6 +3237,9 @@ def _get_patches(installed_only=False):
             if inst != 'i':
                 patches[advisory_id]['installed'] = False
 
+    if parsing_errors:
+        log.warning("Skipped some unexpected output while running '{0}' to list patches. Please check output".format(" ".join(cmd)))
+
     if installed_only:
         patches = {k: v for k, v in patches.items() if v['installed']}
     return patches
-- 
2.29.2


openSUSE Build Service is sponsored by