diff options
author | Shane Bradley <sbradley@redhat.com> | 2016-01-29 12:06:17 -0500 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2016-02-01 16:52:39 +0000 |
commit | 04d412816de2e4053f43956adf536272a2ddc19c (patch) | |
tree | 41857f013d3632a59327cc66ae658f0dfa57b7eb | |
parent | 94350cc0de2c63632f0e7aa04730b991d21bde7f (diff) | |
download | sos-04d412816de2e4053f43956adf536272a2ddc19c.tar.gz |
[utilities] Support glob expansion in command arguments
Historically, when calling an external process, sos relied on the
use of a shell to perform glob expansion on arguments passed to
the command.
This potentially exposes sos and its children to the entire gamut
of shell expansion and all the problems associated with it and
this is part of the reason that use of a shell in callouts was
disabled in commit 46b6c3d (Issue #253).
While full shell syntax is undesirable for many reasons the use
of globs to express path arguments to external commands is very
useful and widely applied: restore this limited support for
shell-like syntax using the python glob.glob module and expand
any argument that is a valid glob into its resulting arguments.
Fixes: #752
Signed-off-by: Shane Bradley <sbradley@redhat.com>
-rw-r--r-- | sos/utilities.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/sos/utilities.py b/sos/utilities.py index 453b75f0..a8d4cf81 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -22,6 +22,7 @@ import logging import fnmatch import errno import shlex +import glob from contextlib import closing @@ -133,8 +134,16 @@ def sos_get_command_output(command, timeout=300, stderr=False, if not six.PY3: command = command.encode('utf-8', 'ignore') args = shlex.split(command) + # Expand arguments that are wildcard paths. + expanded_args = [] + for arg in args: + expanded_arg = glob.glob(arg) + if expanded_arg: + expanded_args.extend(expanded_arg) + else: + expanded_args.append(arg) try: - p = Popen(args, shell=False, stdout=PIPE, + p = Popen(expanded_args, shell=False, stdout=PIPE, stderr=STDOUT if stderr else PIPE, bufsize=-1, env=cmd_env, close_fds=True, preexec_fn=_child_prep_fn) |