Add quotes to prevent potential word splittings#590
Open
zzmic wants to merge 1 commit intoRenderKit:masterfrom
Open
Add quotes to prevent potential word splittings#590zzmic wants to merge 1 commit intoRenderKit:masterfrom
zzmic wants to merge 1 commit intoRenderKit:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates scripts/download_gfx.sh to quote shell variables in command invocations to prevent unintended word-splitting (ShellCheck SC2086), improving robustness when inputs contain spaces or other special characters.
Changes:
- Quote positional parameter checks and path arguments used with
mkdir,cd,cp, andrm. - Quote URL and package expansions in
curlanddpkgcalls. - Quote regex variable usage in
grep -Efor consistency (but see review comments for a correctness concern).
Comments suppressed due to low confidence (1)
scripts/download_gfx.sh:8
- The usage guard only checks whether $3 is empty, but the script can still be invoked with an empty gfx-driver (e.g., passing "" as
$1). That leads to creating/removing "/tmp/" and using an empty driver path elsewhere. Consider validating argument count (e.g., $ # == 3) and rejecting empty $1/$2 explicitly.
if [ -z "$3" ]; then
echo "ERROR: usage $0 gfx-driver target-directory token"
echo " gfx-driver: URL to the driver packages relative to artifactory URL (e.g. gfx-driver-builds/ci/master/gfx-driver-ci-master-9999/artifacts/Linux/Ubuntu/22.04/Release"
echo " token: access token to (artifactory) repository"
exit 1
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
34
to
47
| @@ -40,57 +40,57 @@ if [[ $GFX_DRIVER == *"linux"* ]] || [[ $GFX_DRIVER == *"Linux"* ]] ; then | |||
| else | |||
| DEBS="level-zero|intel-level-zero-gpu|intel-opencl-icd|libigc1|libigc-tools|libigdfcl1|libigdgmm" | |||
| fi | |||
| PACKAGES=$(curl -H "X-JFrog-Art-Api:$TOKEN" -s $URL | | |||
|
|
|||
| PACKAGES=$(curl -H "X-JFrog-Art-Api:$TOKEN" -s "$URL" | | |||
| sed 's/<a href/\n<a href/g' | sed 's/.deb"/.deb"\n/g' | | |||
| grep -o '".*"' | grep deb | tr -d '"' | grep -E $DEBS | | |||
| grep -o '".*"' | grep deb | tr -d '"' | grep -E "$DEBS" | | |||
| grep -v devel | grep -v dev | grep -v debuginfo) | |||
Comment on lines
+44
to
47
| PACKAGES=$(curl -H "X-JFrog-Art-Api:$TOKEN" -s "$URL" | | ||
| sed 's/<a href/\n<a href/g' | sed 's/.deb"/.deb"\n/g' | | ||
| grep -o '".*"' | grep deb | tr -d '"' | grep -E $DEBS | | ||
| grep -o '".*"' | grep deb | tr -d '"' | grep -E "$DEBS" | | ||
| grep -v devel | grep -v dev | grep -v debuginfo) |
Comment on lines
+93
to
+94
| cd "${CUR_DIR}" | ||
| rm -rf "/tmp/${GFX_DRIVER}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As the title suggests, this PR includes the commit that adds quotes to several commands in
scripts/download_gfx.shto prevent potential word splittings (related to https://www.shellcheck.net/wiki/SC2086). In particular, the previous line ofrm -rf /tmp/${GFX_DRIVER}is concerning, since${GFX_DRIVER}is unquoted, (1) if it contains whitespaces, it would be split into multiple arguments torm -rf, and (2) if it is empty or resolves unexpectedly, the command becomesrm -rf /tmp/, which is even more catastrophic. Other quotes are added more for the sake of consistency, even though they do address the valid concern of word splitting (but they are not as concerning asrm -rf /tmp/${GFX_DRIVER}).