diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2013-04-26 16:31:13 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2013-04-26 16:31:13 +0100 |
commit | d93908860b7d22388b1ace5082c197b6925752cb (patch) | |
tree | 77aa2ec202c38eaa4122cd2bcba0b5300f6a95b2 | |
parent | fbbb6ace22fe97928f78d0058559defeccc472cc (diff) | |
download | sos-d93908860b7d22388b1ace5082c197b6925752cb.tar.gz |
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 <module>
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 <bmr@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 4 |
1 files changed, 4 insertions, 0 deletions
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): |