Skip to content

Commit cf1b308

Browse files
committed
change: oscap-ssh: simplify command_array_to_string
- use printf %q instead of home made implementation - use $@ - there is no point using fancy array arrayref and eval in this simple use case - printf just iterates parameters and "$@" works just fine - changes usage: from: command_array_to_string arref to: command_array_to_string "${array[@]}"
1 parent 185453d commit cf1b308

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

utils/oscap-ssh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,10 @@ function scp_retreive_from_temp_dir {
123123
scp -o ControlPath="$MASTER_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$SSH_HOST:$REMOTE_TEMP_DIR/$1" "$2"
124124
}
125125

126-
# $1: The name of the array holding command elements
127-
# Returns: String, where individual command components are double-quoted, so they are not interpreted by the shell.
128-
# For example, an array ('-p' '(all)') will be transformed to "\"-p\" \"(all)\"", so after the shell expansion, it will end up as "-p" "(all)".
126+
# $@: Elements to be quoted if needed
127+
# Returns: String, where individual command components are joined, and quoted if necessary, so they are not interpreted by the shell.
129128
function command_array_to_string {
130-
eval "printf '\"%s\" ' \"\${$1[@]}\""
129+
printf "%q " "$@"
131130
}
132131

133132
function first_argument_is_sudo {
@@ -305,9 +304,9 @@ echo "Starting the evaluation..."
305304
# dumped into PWD, and we can't be sure by the file names - we need controlled
306305
# environment
307306
if [ -z "$OSCAP_SUDO" ]; then
308-
ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; oscap $(command_array_to_string oscap_args)" "$SSH_TTY_ALLOCATION_OPTION"
307+
ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; oscap $(command_array_to_string "${oscap_args[@]}")" "$SSH_TTY_ALLOCATION_OPTION"
309308
else
310-
OSCAP_CMD="oscap $(command_array_to_string oscap_args); rc=\$?; chown \$SUDO_USER $REMOTE_TEMP_DIR/*; exit \$rc"
309+
OSCAP_CMD="oscap $(command_array_to_string "${oscap_args[@]}"); rc=\$?; chown \$SUDO_USER $REMOTE_TEMP_DIR/*; exit \$rc"
311310
ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO sh -c '$OSCAP_CMD'" "$SSH_TTY_ALLOCATION_OPTION"
312311
fi
313312
OSCAP_EXIT_CODE=$?

0 commit comments

Comments
 (0)