Skip to content

Double quote variables to prevent globbing and word splitting #17235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AleksandrLiber
Copy link

@AleksandrLiber AleksandrLiber commented Apr 10, 2025

Motivation and Context

It has been quite some time since shellcheck has been run against the performance test library. Recently there was an issue where $SUDO_COMMAND splitting incorrectly causes the result file paths to be generated incorrectly. We want to fix this issue and get ahead of any other potential issues.

Description

This change goes through and quotes variables where appropriate to avoid issues with incorrect splitting.

How Has This Been Tested?

Ran the perf suite to ensure still working as expected

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

@github-actions github-actions bot added the Status: Work in Progress Not yet ready for general review label Apr 10, 2025
@AleksandrLiber AleksandrLiber marked this pull request as ready for review April 14, 2025 01:41
@github-actions github-actions bot added Status: Code Review Needed Ready for review and testing and removed Status: Work in Progress Not yet ready for general review labels Apr 14, 2025
Copy link
Contributor

@tonynguien tonynguien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks for doing this!

This change goes through and quotes variables where appropriate to
avoid issues with incorrect splitting. The performance tests ran into
an issue with $SUDO_COMMAND splitting incorrectly because it was not
quoted. This change fixes that issue and hopefully gets ahead of any
other similar problems.

Signed-off-by: Aleksandr Liber <[email protected]>
Requires-builders: test perf
Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a shell guru, but some things look suspicious to me.

@@ -105,7 +105,7 @@ function do_fio_run_impl
# the default filesystem (e.g. against a clone).
#
export DIRECTORY=$(get_directory)
log_note "DIRECTORY: " $DIRECTORY
log_note "DIRECTORY: " "$DIRECTORY"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think log_note cares about number of arguments, but if we want to wrap the variable into quotes, I don't think we need to close and reopen them before it.


# Define output file
typeset logbase="$(get_perf_output_dir)/$(basename \
$SUDO_COMMAND)"
"$SUDO_COMMAND")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you are adding quotes inside quotes. Doesn't it need escaping, or something?

typeset outfile="$logbase.fio.$suffix"

# Start the load
if [[ $NFS -eq 1 ]]; then
log_must ssh -t $NFS_USER@$NFS_CLIENT "
log_must ssh -t "$NFS_USER"@"$NFS_CLIENT" "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, do we need to close quotes around @?

log_must fio --output-format=${PERF_FIO_FORMAT} \
--output $outfile $FIO_SCRIPTS/$script
log_must fio --output-format="${PERF_FIO_FORMAT}" \
--output "$outfile" "$FIO_SCRIPTS"/"$script"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, wo we need to close/reopen quotes around /?

done
IFS=$oIFS

typeset idx=0
while [[ $idx -lt "${#collect_scripts[@]}" ]]; do
typeset logbase="$(get_perf_output_dir)/$(basename \
$SUDO_COMMAND)"
"$SUDO_COMMAND")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again quotes inside quotes.

@@ -354,13 +354,13 @@ function populate_perf_filesystems

function get_nfilesystems
{
typeset filesystems=( $TESTFS )
typeset filesystems=("$TESTFS")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an array initialization. Do we really want to convert empty variable into one element array of empty string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants