Skip to content

fix(SC2114): issue SC2114 against glob - #3583

Merged
koalaman merged 1 commit into
koalaman:masterfrom
e-kwsm:2833
Oct 26, 2026
Merged

koalaman merged 1 commit into
koalaman:masterfrom
e-kwsm:2833

Conversation

@e-kwsm

@e-kwsm e-kwsm commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

getLiteralString returns Nothing against glob patterns such as /*, thus SC2115 was returned; use getGlobOrLiteralString to issue SC2114

resolve #2833

getLiteralString returns Nothing against glob patterns such as `/*`,
thus SC2115 was returned; use getGlobOrLiteralString to issue SC2114

resolve koalaman#2833
Comment on lines 1145 to 1147
prop_checkCatastrophicRm3 = verifyNot checkCatastrophicRm "rm -r /home/${USER:?}/*"
prop_checkCatastrophicRm4 = verify checkCatastrophicRm "rm -fr /home/$(whoami)/*"
prop_checkCatastrophicRm5 = verifyNot checkCatastrophicRm "rm -r /home/${USER:-thing}/*"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

rm -rf /home/${USER:?}/* /home/${USER:-thing}/*

Aren’t these destructive?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Very destructive, but also intentional.

The idea was the reduce false positives in user provisioning scripts and such that intentionally delete a user's home directory, but triggering on scripts where latent bugs may mean you delete all home directories.

prop_checkCatastrophicRm1 = verify checkCatastrophicRm "rm -r $1/$2"
prop_checkCatastrophicRm2 = verify checkCatastrophicRm "rm -r /home/$foo"
prop_checkCatastrophicRm3 = verifyNot checkCatastrophicRm "rm -r /home/${USER:?}/*"
prop_checkCatastrophicRm4 = verify checkCatastrophicRm "rm -fr /home/$(whoami)/*"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As of 776ed08,

$ shellcheck -s sh -f gcc - <<< 'rm -fr /home/"$(whoami)"/*'
-:1:8: warning: Use "${var:?}" to ensure this never expands to /home/* . [SC2115]

The hint is unhelpful, and nonnull string leads to a fatal issue.
SC2114?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is indeed pretty unhelpful. I updated the wiki page https://github.com/koalaman/shellcheck/wiki/SC2115 to suggest putting command expansions in variables first, but ideally this would be a more helpful message

@koalaman
koalaman merged commit e04ae2c into koalaman:master Oct 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SC2115 warns even when there's nothing to expand

2 participants