Merge pull request #18095 from Homebrew/secure-env-files

bin/brew: tighten check in `export_homebrew_env_file`
This commit is contained in:
Carlo Cabrera 2024-08-20 17:49:49 +08:00 committed by GitHub
commit 75ab63bedc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -108,14 +108,14 @@ HOMEBREW_LIBRARY="${HOMEBREW_REPOSITORY}/Library"
# Load Homebrew's variable configuration files from disk.
export_homebrew_env_file() {
local env_file
local env_file="${1}"
local homebrew_env_regex="^HOMEBREW_[A-Z_]+=[^=]*$"
env_file="${1}"
[[ -r "${env_file}" ]] || return 0
while read -r line
do
# only load HOMEBREW_* lines
[[ "${line}" = "HOMEBREW_"* ]] || continue
[[ "${line}" =~ ${homebrew_env_regex} ]] || continue
export "${line?}"
done <"${env_file}"
}