From c39c7bbca984922dc8c9f33add65a5f5662fcba4 Mon Sep 17 00:00:00 2001 From: William Brown Date: Jan 13 2020 19:48:06 +0000 Subject: Ticket 50798 - incorrect bytes in format string Bug Description: We did not use ensure_bytes on a command output in format strings. Python 3 subprocess returens bytes, but format string expects utf8 Fix Description: Wrap the values in the correct safety wrappers. https://pagure.io/389-ds-base/issue/50798 Author: William Brown Review by: mreynolds, mhonek (Thanks) --- diff --git a/src/lib389/lib389/instance/remove.py b/src/lib389/lib389/instance/remove.py index c9a872e..41eaeb4 100644 --- a/src/lib389/lib389/instance/remove.py +++ b/src/lib389/lib389/instance/remove.py @@ -102,7 +102,10 @@ def remove_ds_instance(dirsrv, force=False): result = subprocess.run(["systemctl", "disable", "dirsrv@{}".format(dirsrv.serverid)], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - _log.debug(f"CMD: {' '.join(result.args)} ; STDOUT: {result.stdout} ; STDERR: {result.stderr}") + args = ' '.join(ensure_list_str(result.args)) + stdout = ensure_str(result.stdout) + stderr = ensure_str(result.stderr) + _log.debug(f"CMD: {args} ; STDOUT: {stdout} ; STDERR: {stderr}") _log.debug("Removing %s" % tmpfiles_d_path) try: diff --git a/src/lib389/lib389/instance/setup.py b/src/lib389/lib389/instance/setup.py index c1a85e5..ead3db1 100644 --- a/src/lib389/lib389/instance/setup.py +++ b/src/lib389/lib389/instance/setup.py @@ -783,7 +783,10 @@ class SetupDs(object): # Should create the symlink we need, but without starting it. result = subprocess.run(["systemctl", "enable", "dirsrv@%s" % slapd['instance_name']], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - self.log.debug(f"CMD: {' '.join(result.args)} ; STDOUT: {result.stdout} ; STDERR: {result.stderr}") + args = ' '.join(ensure_list_str(result.args)) + stdout = ensure_str(result.stdout) + stderr = ensure_str(result.stderr) + self.log.debug(f"CMD: {args} ; STDOUT: {stdout} ; STDERR: {stderr}") # Setup tmpfiles_d tmpfile_d = ds_paths.tmpfiles_d + "/dirsrv-" + slapd['instance_name'] + ".conf" diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py index a2e57c1..b3a7272 100644 --- a/src/lib389/lib389/utils.py +++ b/src/lib389/lib389/utils.py @@ -309,7 +309,10 @@ def selinux_label_port(port, remove_label=False): "-p", "tcp", str(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - log.debug(f"CMD: {' '.join(result.args)} ; STDOUT: {result.stdout} ; STDERR: {result.stderr}") + args = ' '.join(ensure_list_str(result.args)) + stdout = ensure_str(result.stdout) + stderr = ensure_str(result.stderr) + log.debug(f"CMD: {args} ; STDOUT: {stdout} ; STDERR: {stderr}") return except (OSError, subprocess.CalledProcessError) as e: label_ex = e