Skip to content

Commit 62082b7

Browse files
committed
Made oscap-ssh to work with shell-sensitive args.
Fixes e.g. the problem of oscap arguments -p (all). Now, (all) is escaped, so it not intercepted by the shell.
1 parent 2480709 commit 62082b7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

utils/oscap-ssh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ function scp_retreive_from_temp_dir {
115115
scp -o ControlPath="$MASTER_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$SSH_HOST:$REMOTE_TEMP_DIR/$1" "$2"
116116
}
117117

118+
# $1: The name of the array holding command elements
119+
# Returns: String, where individual command components are double-quoted, so they are not interpreted by the shell.
120+
# For example, an array ('-p' '(all)') will be transformed to "\"-p\" \"(all)\"", so after the shell expansion, it will end up as "-p" "(all)".
121+
function command_array_to_string {
122+
eval "printf '\"%s\" ' \"\${$1[@]}\""
123+
}
124+
118125
function first_argument_is_sudo {
119126
[ "$1" == "sudo" ] || [ "$1" == "--sudo" ]
120127
return $?
@@ -273,7 +280,7 @@ echo "Starting the evaluation..."
273280
# changing directory because of --oval-results support. oval results files are
274281
# dumped into PWD, and we can't be sure by the file names - we need controlled
275282
# environment
276-
ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO oscap ${oscap_args[*]}" "$SSH_TTY_ALLOCATION_OPTION"
283+
ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO oscap $(command_array_to_string oscap_args)" "$SSH_TTY_ALLOCATION_OPTION"
277284
OSCAP_EXIT_CODE=$?
278285
echo "oscap exit code: $OSCAP_EXIT_CODE"
279286

0 commit comments

Comments
 (0)