Skip to content

Commit 6501f73

Browse files
authored
fix: do not allow GREP_XXX env vars from breaking rlocation (#36)
The grep command can be influenced by `GREP_XXX` environment variables. If set, they can affect the behavior/output of the command, causing `rlocation` to fail.
1 parent 0713632 commit 6501f73

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

shell/runfiles/runfiles.bash

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ esac
113113
# Does not exit with a non-zero exit code if no match is found and performs a case-insensitive
114114
# search on Windows.
115115
function __runfiles_maybe_grep() {
116-
grep $_RLOCATION_GREP_CASE_INSENSITIVE_ARGS "$@" || test $? = 1;
116+
# The GREP_XXX variables influence how grep behaves. Specifically, they can
117+
# affect the output from the grep command.
118+
GREP_COLOR="" GREP_OPTIONS="" grep $_RLOCATION_GREP_CASE_INSENSITIVE_ARGS "$@" || test $? = 1;
117119
}
118120
export -f __runfiles_maybe_grep
119121

tests/runfiles/runfiles_test.bash

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,13 @@ function test_directory_based_envvars() {
522522
[[ -z "${RUNFILES_MANIFEST_FILE:-}" ]] || fail
523523
}
524524

525+
function test_with_grep_env_vars_set() {
526+
# These influence how grep behaves.
527+
export GREP_COLOR='1;35;40'
528+
export GREP_OPTIONS='--color=always'
529+
test_init_manifest_based_runfiles
530+
}
531+
525532
function main() {
526533
local -r manifest_file="${RUNFILES_MANIFEST_FILE:-}"
527534
local -r dir="${RUNFILES_DIR:-}"

0 commit comments

Comments
 (0)