Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew.sh: Don't allow system tmp dirs as prefixes #4397

Merged
merged 14 commits into from Jul 3, 2018
Merged
36 changes: 23 additions & 13 deletions Library/Homebrew/brew.sh
Expand Up @@ -104,26 +104,20 @@ then
HOMEBREW_SYSTEM_GIT_TOO_OLD="1"
fi

if [[ -z "$HOMEBREW_CACHE" ]]
then
HOMEBREW_CACHE="$HOME/Library/Caches/Homebrew"
fi
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOME}/Library/Caches/Homebrew}"

HOMEBREW_TEMP="${HOMEBREW_TEMP:-/private/tmp}"
else
HOMEBREW_PROCESSOR="$(uname -m)"
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew"
[[ -n "$HOMEBREW_LINUX" ]] && HOMEBREW_OS_VERSION="$(lsb_release -sd 2>/dev/null)"
: "${HOMEBREW_OS_VERSION:=$(uname -r)}"
HOMEBREW_OS_USER_AGENT_VERSION="$HOMEBREW_OS_VERSION"

if [[ -z "$HOMEBREW_CACHE" ]]
then
if [[ -n "$XDG_CACHE_HOME" ]]
then
HOMEBREW_CACHE="$XDG_CACHE_HOME/Homebrew"
else
HOMEBREW_CACHE="$HOME/.cache/Homebrew"
fi
fi
CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}"

HOMEBREW_TEMP="${HOMEBREW_TEMP:-/tmp}"
fi

if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" &&
Expand All @@ -144,6 +138,7 @@ export HOMEBREW_BREW_FILE
export HOMEBREW_PREFIX
export HOMEBREW_REPOSITORY
export HOMEBREW_LIBRARY
export HOMEBREW_TEMP

# Declared in brew.sh
export HOMEBREW_VERSION
Expand Down Expand Up @@ -294,6 +289,21 @@ EOS
}
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" &&
"$HOMEBREW_PREFIX" != "$HOMEBREW_REPOSITORY" &&
"$HOMEBREW_CELLAR" = "$HOMEBREW_REPOSITORY/Cellar" ]]
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/config.rb
Expand Up @@ -39,7 +39,7 @@
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
HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/tmp"))
HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"]).realpath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will crash when the dir doesn't exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Fixing 😭

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


unless defined? HOMEBREW_LIBRARY_PATH
# Root of the Homebrew code base
Expand Down