-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Changes from 11 commits
35138dd
949c0cc
42bd544
b6a0b04
c552e65
696a1d1
d7cdc9b
8e4aab9
72bc6b1
a8bcb5d
039a4ee
bde7c6b
68d3dc1
fd01415
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,8 @@ then | |
then | ||
HOMEBREW_CACHE="$HOME/Library/Caches/Homebrew" | ||
fi | ||
|
||
HOMEBREW_TEMP="${HOMEBREW_TEMP:-/private/tmp}" | ||
else | ||
HOMEBREW_PROCESSOR="$(uname -m)" | ||
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew" | ||
|
@@ -124,6 +126,8 @@ else | |
HOMEBREW_CACHE="$HOME/.cache/Homebrew" | ||
fi | ||
fi | ||
|
||
HOMEBREW_TEMP="${HOMEBREW_TEMP:-/tmp}" | ||
fi | ||
|
||
if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && | ||
|
@@ -144,6 +148,7 @@ export HOMEBREW_BREW_FILE | |
export HOMEBREW_PREFIX | ||
export HOMEBREW_REPOSITORY | ||
export HOMEBREW_LIBRARY | ||
export HOMEBREW_TEMP | ||
|
||
# Declared in brew.sh | ||
export HOMEBREW_VERSION | ||
|
@@ -294,6 +299,19 @@ EOS | |
} | ||
check-run-command-as-root | ||
|
||
check-prefix-is-not-tmpdir() { | ||
if [[ "${HOMEBREW_PREFIX}" = "${HOMEBREW_TEMP}"* ]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wants guarded to macOS only, check against the system temp rather than just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I might be misunderstanding, but: won't this leave open the case where they set both their prefix and their temp to something weird, e.g., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @woodruffw Ok so is it fine to e.g. have the prefix in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, exactly. |
||
then | ||
odie <<EOS | ||
Your HOMEBREW_PREFIX is in the system temporary directory, which Homebrew | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe worth just saying e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that the connection between The relocation code at fault isn't used on Linux, so Linuxbrew users might not encounter this problem at all. I'll confirm that in a bit with some local testing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We should ensure that the wording makes that clear and the logic is as minimal as possible to the actual problems we've seen people experience. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is when the prefix is in the |
||
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 system temporary directory. | ||
EOS | ||
fi | ||
} | ||
check-prefix-is-not-tmpdir | ||
|
||
if [[ "$HOMEBREW_PREFIX" = "/usr/local" && | ||
"$HOMEBREW_PREFIX" != "$HOMEBREW_REPOSITORY" && | ||
"$HOMEBREW_CELLAR" = "$HOMEBREW_REPOSITORY/Cellar" ]] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will crash when the dir doesn't exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. Fixing 😭 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
||
unless defined? HOMEBREW_LIBRARY_PATH | ||
# Root of the Homebrew code base | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to defining here. I wonder if it's worth doing just the same
-z
as above for consistency? Alternatively; replace the-z
s that have no complex logic with this form?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of replacing with the
:-
form, since it's the standard bashism for a default value and we use similar bashisms elsewhere in the code.