From d93908860b7d22388b1ace5082c197b6925752cb Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Fri, 26 Apr 2013 16:31:13 +0100 Subject: Fix UnboundLocalError during command output substitution Plugin.do_cmd_output_sub() assumes that the list of executed commands is non-empty if the list of commands requested is non-empty. This can be false (e.g. when a command is run speculatively and the binary is not present) leading to an unbound variable exception as the code never sets the variable used as the return value: Traceback (most recent call last): File "/usr/sbin/sosreport", line 23, in main(sys.argv[1:]) File "/usr/lib/python2.7/dist-packages/sos/sosreport.py", line 1154, in main sos.execute() UnboundLocalError: local variable 'replacements' referenced before assignment > /usr/lib/python2.7/dist-packages/sos/plugins/__init__.py(197)do_cmd_output_sub() -> return replacements Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 435d69fe..1a28a1e3 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -174,6 +174,10 @@ class Plugin(object): globstr = '*' + cmd + '*' self.soslog.debug("substituting '%s' for '%s' in commands matching %s" % (subst, regexp, globstr)) + + if not self.executed_commands: + return 0 + try: for called in self.executed_commands: if fnmatch.fnmatch(called['exe'], globstr): -- cgit