From 994a109883405bd0eec1ce378e9c424240e46510 Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Nov 14 2019 18:59:06 +0000 Subject: Issue 50634 - Fix CLI error parsing for non-string values Bug Description: Sometimes the error message has int values and it makes ' - '.join() function to fail. Fix Description: Use a list comprehension to change the dict values to str. https://pagure.io/389-ds-base/issue/50634 Reviewed by: ? --- diff --git a/src/lib389/cli/dsconf b/src/lib389/cli/dsconf index 2059a06..6e3ef19 100755 --- a/src/lib389/cli/dsconf +++ b/src/lib389/cli/dsconf @@ -143,7 +143,7 @@ if __name__ == '__main__': if args and args.json: sys.stderr.write(json.dumps(msg)) else: - log.error("Error: %s" % " - ".join(msg.values())) + log.error("Error: %s" % " - ".join(str(val) for val in msg.values())) result = False disconnect_instance(inst) diff --git a/src/lib389/cli/dscreate b/src/lib389/cli/dscreate index b516eb9..b9c5b48 100755 --- a/src/lib389/cli/dscreate +++ b/src/lib389/cli/dscreate @@ -76,7 +76,7 @@ if __name__ == '__main__': except Exception as e: log.debug(e, exc_info=True) msg = format_error_to_dict(e) - log.error("Error: %s" % " - ".join(msg.values())) + log.error("Error: %s" % " - ".join(str(val) for val in msg.values())) result = False # Done! diff --git a/src/lib389/cli/dsctl b/src/lib389/cli/dsctl index 3be9540..9bca1e9 100755 --- a/src/lib389/cli/dsctl +++ b/src/lib389/cli/dsctl @@ -127,7 +127,7 @@ if __name__ == '__main__': except Exception as e: log.debug(e, exc_info=True) msg = format_error_to_dict(e) - log.error("Error: %s" % " - ".join(msg.values())) + log.error("Error: %s" % " - ".join(str(val) for val in msg.values())) result = False disconnect_instance(inst) diff --git a/src/lib389/cli/dsidm b/src/lib389/cli/dsidm index da246b5..fb0b6a2 100755 --- a/src/lib389/cli/dsidm +++ b/src/lib389/cli/dsidm @@ -133,7 +133,7 @@ if __name__ == '__main__': except Exception as e: log.debug(e, exc_info=True) msg = format_error_to_dict(e) - log.error("Error: %s" % " - ".join(msg.values())) + log.error("Error: %s" % " - ".join(str(val) for val in msg.values())) result = False disconnect_instance(inst) diff --git a/src/lib389/lib389/cli_base/__init__.py b/src/lib389/lib389/cli_base/__init__.py index 12b1c51..e2e6c90 100644 --- a/src/lib389/lib389/cli_base/__init__.py +++ b/src/lib389/lib389/cli_base/__init__.py @@ -422,6 +422,8 @@ def format_error_to_dict(exception): # We should fix the code here after the issue is fixed errmsg = str(exception) try: + # The function literal_eval parses the string and returns only if it's a literal. + # Also, the code is never executed. So there is no reason for a security risk. msg = ast.literal_eval(errmsg) except Exception: msg = {'desc': errmsg}