OSDN Git Service

git-prompt.sh: don't put unsanitized branch names in $PS1
authorRichard Hansen <rhansen@bbn.com>
Mon, 21 Apr 2014 23:53:09 +0000 (19:53 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Apr 2014 19:37:53 +0000 (12:37 -0700)
commit8976500cbbb13270398d3b3e07a17b8cc7bff43f
treeb7dc68f4d791a2b9210e8fe0b43abf80117d43b9
parent7bbc4e8fdb33e0a8e42e77cc05460d4c4f615f4d
git-prompt.sh: don't put unsanitized branch names in $PS1

Both bash and zsh subject the value of PS1 to parameter expansion,
command substitution, and arithmetic expansion.  Rather than include
the raw, unescaped branch name in PS1 when running in two- or
three-argument mode, construct PS1 to reference a variable that holds
the branch name.  Because the shells do not recursively expand, this
avoids arbitrary code execution by specially-crafted branch names such
as '$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)'.

Signed-off-by: Richard Hansen <rhansen@bbn.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-prompt.sh
t/t9903-bash-prompt.sh