Quote "$@" throughout the shift script (#1081)#1085
Open
dduugg wants to merge 1 commit into
Open
Conversation
Every subcommand that forwarded arguments used an unquoted $@, at each hop of the call chain ( dispatcher -> sub_* -> sub_compose -> docker ). Under bash that re-splits each argument on whitespace and glob-expands it, so `./shift mysql -e "SELECT * FROM calevent"` reached mysql as a dozen mangled tokens ( the * expanded to the repo directory listing ), and mysql printed its usage text instead of running the query. Quote "$@" at every level so arguments with spaces or glob characters pass through intact. No behavior change for the space-free arguments the other subcommands take.
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.
Fixes #1081.
Every
./shiftsubcommand that forwards arguments used an unquoted$@, at each hop of the call chain (dispatcher ->sub_*->sub_compose->docker).shiftis a bash script, and unquoted$@in bash re-splits each argument on whitespace and then glob-expands the results.The most visible casualty is
./shift mysql -e "<sql>", which never runs the SQL and instead prints mysql's usage text, because the SQL string is split into many arguments before mysql sees it.The change
Quote
"$@"at all 18 forwarding sites (the dispatcher,sub_compose, and everysub_*that passes arguments through). The space-free service names that the other subcommands take (./shift logs node,./shift down) are unaffected.Scope is limited to the
$@word-splitting bug. The${MYSQL_USER}/${MYSQL_DATABASE}values on the mysql lines are controlled and space-free, so they are left as-is to keep the diff focused.Verification
Driving the actual script with a stubbed
dockeronPATH, so the arguments that would reachdocker composecan be counted. Argument used:-e "SELECT * FROM calevent WHERE title = 'a b';"(a glob and a space, the two failure modes):Ordinary subcommands still pass their arguments correctly (
./shift logs node->compose logs --tail=50 -f node;./shift down->compose down), and the unknown-subcommand error path (exit 127) still fires.bash -n shiftparses clean.This bug also bit the verification steps originally written into #1077; the workaround there was to pipe SQL via
./shift mysql-pipe(stdin) instead of passing it as an argument.