From f7b5792b7103827dbb9308821b33dbb4ce15ede4 Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Mon, 9 Aug 2021 12:34:15 +0200 Subject: [PATCH] Fix error handling in openscap module --- salt/modules/openscap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/salt/modules/openscap.py b/salt/modules/openscap.py index f75e1c5e6b3..216fd89eef6 100644 --- a/salt/modules/openscap.py +++ b/salt/modules/openscap.py @@ -153,7 +153,9 @@ def xccdf_eval(xccdffile, ovalfiles=None, **kwargs): tempdir = tempfile.mkdtemp() proc = Popen(cmd_opts, stdout=PIPE, stderr=PIPE, cwd=tempdir) (stdoutdata, error) = proc.communicate() - success = _OSCAP_EXIT_CODES_MAP[proc.returncode] + success = _OSCAP_EXIT_CODES_MAP.get(proc.returncode, False) + if proc.returncode < 0: + error += "\nKilled by signal {}\n".format(proc.returncode).encode('ascii') returncode = proc.returncode if success: __salt__["cp.push_dir"](tempdir) @@ -202,7 +204,9 @@ def xccdf(params): tempdir = tempfile.mkdtemp() proc = Popen(shlex.split(cmd), stdout=PIPE, stderr=PIPE, cwd=tempdir) (stdoutdata, error) = proc.communicate() - success = _OSCAP_EXIT_CODES_MAP[proc.returncode] + success = _OSCAP_EXIT_CODES_MAP.get(proc.returncode, False) + if proc.returncode < 0: + error += "\nKilled by signal {}\n".format(proc.returncode).encode('ascii') returncode = proc.returncode if success: __salt__["cp.push_dir"](tempdir)