From a8292af92fa9d19123f802128d9f0ef12e04e5c4 Mon Sep 17 00:00:00 2001 From: oGre Date: Wed, 3 May 2017 16:17:20 +0200 Subject: [PATCH 1/2] Check the syntax of .bash-git-rc before sourcing it --- gitprompt.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index 78f4de8..c61e632 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -346,7 +346,13 @@ function setGitPrompt() { unset GIT_PROMPT_SHOW_UNTRACKED_FILES if [[ -e "$repo/.bash-git-rc" ]]; then - source "$repo/.bash-git-rc" + # The config file can only contain variable declarations on the form A_B=0 or G_P=all + local CONFIG_SYNTAX="^[A-Z_]+=[0-9a-z]+$" + if egrep -q -v "$CONFIG_SYNTAX" "$repo/.bash-git-rc"; then + echo ".bash-git-rc can only contain variable values on the form NAME=value. Ignoring file." >&2 + else + source "$repo/.bash-git-rc" + fi fi if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then From 19d941d4094f6b7518de3e191f7983d34789e689 Mon Sep 17 00:00:00 2001 From: oGre Date: Wed, 3 May 2017 19:29:51 +0200 Subject: [PATCH 2/2] Just allow the whitelisted variable names --- gitprompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitprompt.sh b/gitprompt.sh index c61e632..b85da60 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -347,7 +347,7 @@ function setGitPrompt() { if [[ -e "$repo/.bash-git-rc" ]]; then # The config file can only contain variable declarations on the form A_B=0 or G_P=all - local CONFIG_SYNTAX="^[A-Z_]+=[0-9a-z]+$" + local CONFIG_SYNTAX="^(FETCH_REMOTE_STATUS|GIT_PROMPT_SHOW_UNTRACKED_FILES|GIT_PROMPT_IGNORE)=[0-9a-z]+$" if egrep -q -v "$CONFIG_SYNTAX" "$repo/.bash-git-rc"; then echo ".bash-git-rc can only contain variable values on the form NAME=value. Ignoring file." >&2 else