Merge pull request #4397 from woodruffw/forbid-temp-prefix

brew.sh: Don't allow system tmp dirs as prefixes
This commit is contained in:
Mike McQuaid 2018-07-03 08:31:40 +01:00 committed by GitHub
commit 09ee556833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 14 deletions

View File

@ -104,10 +104,9 @@ then
HOMEBREW_FORCE_BREWED_GIT="1" HOMEBREW_FORCE_BREWED_GIT="1"
fi fi
if [[ -z "$HOMEBREW_CACHE" ]] HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOME}/Library/Caches/Homebrew}"
then
HOMEBREW_CACHE="$HOME/Library/Caches/Homebrew" HOMEBREW_TEMP="${HOMEBREW_TEMP:-/private/tmp}"
fi
else else
HOMEBREW_PROCESSOR="$(uname -m)" HOMEBREW_PROCESSOR="$(uname -m)"
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew" HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew"
@ -115,15 +114,10 @@ else
: "${HOMEBREW_OS_VERSION:=$(uname -r)}" : "${HOMEBREW_OS_VERSION:=$(uname -r)}"
HOMEBREW_OS_USER_AGENT_VERSION="$HOMEBREW_OS_VERSION" HOMEBREW_OS_USER_AGENT_VERSION="$HOMEBREW_OS_VERSION"
if [[ -z "$HOMEBREW_CACHE" ]] CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
then HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}"
if [[ -n "$XDG_CACHE_HOME" ]]
then HOMEBREW_TEMP="${HOMEBREW_TEMP:-/tmp}"
HOMEBREW_CACHE="$XDG_CACHE_HOME/Homebrew"
else
HOMEBREW_CACHE="$HOME/.cache/Homebrew"
fi
fi
fi fi
if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" &&
@ -153,6 +147,7 @@ export HOMEBREW_BREW_FILE
export HOMEBREW_PREFIX export HOMEBREW_PREFIX
export HOMEBREW_REPOSITORY export HOMEBREW_REPOSITORY
export HOMEBREW_LIBRARY export HOMEBREW_LIBRARY
export HOMEBREW_TEMP
# Declared in brew.sh # Declared in brew.sh
export HOMEBREW_VERSION export HOMEBREW_VERSION
@ -309,6 +304,21 @@ EOS
} }
check-run-command-as-root check-run-command-as-root
check-prefix-is-not-tmpdir() {
[[ -z "${HOMEBREW_MACOS}" ]] && return
if [[ "${HOMEBREW_PREFIX}" = "${HOMEBREW_TEMP}"* ]]
then
odie <<EOS
Your HOMEBREW_PREFIX is in the Homebrew temporary directory, which Homebrew
uses to store downloads and builds. You can resolve this by installing Homebrew to
either the standard prefix (/usr/local) or to a non-standard prefix that is not
in the Homebrew temporary directory.
EOS
fi
}
check-prefix-is-not-tmpdir
if [[ "$HOMEBREW_PREFIX" = "/usr/local" && if [[ "$HOMEBREW_PREFIX" = "/usr/local" &&
"$HOMEBREW_PREFIX" != "$HOMEBREW_REPOSITORY" && "$HOMEBREW_PREFIX" != "$HOMEBREW_REPOSITORY" &&
"$HOMEBREW_CELLAR" = "$HOMEBREW_REPOSITORY/Cellar" ]] "$HOMEBREW_CELLAR" = "$HOMEBREW_REPOSITORY/Cellar" ]]

View File

@ -39,7 +39,7 @@ HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE/"Formula"
HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/").expand_path HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/").expand_path
# Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets # Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets
HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/tmp")) HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"]).realpath
unless defined? HOMEBREW_LIBRARY_PATH unless defined? HOMEBREW_LIBRARY_PATH
# Root of the Homebrew code base # Root of the Homebrew code base