Skip to content

Commit 4abd284

Browse files
committed
git-completion: sanitize the command names
Do not declare/execute commands that contain invalid or special characters. If the autocompleted command contains illegal characters, for example when misspelling `git pull` as `git [ull`, then the user will see an error. This patch adds a character whitelist for commands that strips all but lowercase alphabetic characters and dashes, so that misspells fail silently. This patch uses the `[[` keyword that is not sh-compatible, but it's okay since the change affects BASH and ZSH-specific autocomplete scripts. Signed-off-by: Vladyslav Burzakovskyy <[email protected]>
1 parent aa25c82 commit 4abd284

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

contrib/completion/git-completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,6 +2853,7 @@ __git_support_parseopt_helper () {
28532853
__git_complete_command () {
28542854
local command="$1"
28552855
local completion_func="_git_${command//-/_}"
2856+
[[ "$command" =~ [^a-z-] ]] && return 1
28562857
if ! declare -f $completion_func >/dev/null 2>/dev/null &&
28572858
declare -f _completion_loader >/dev/null 2>/dev/null
28582859
then

contrib/completion/git-completion.zsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ __git_zsh_bash_func ()
116116
emulate -L ksh
117117

118118
local command=$1
119-
120119
local completion_func="_git_${command//-/_}"
120+
121+
[[ "$command" =~ [^a-z-] ]] && return
121122
declare -f $completion_func >/dev/null && $completion_func && return
122123

123124
local expansion=$(__git_aliased_command "$command")

0 commit comments

Comments
 (0)