From 4a11e74307eb7670d1f22d0fd31afc4647f6c42d Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:48:43 +0800 Subject: [PATCH] bin/brew: tighten check in `export_homebrew_env_file` The current glob check will accept lines like HOMEBREW_FOO=bar BAD_ENV_VAR=baz and happily export them, but we don't want that. Let's tighten up the check to reject lines like the above. --- bin/brew | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/brew b/bin/brew index 972bfa3eda..329f642c8c 100755 --- a/bin/brew +++ b/bin/brew @@ -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}" }