From 9f072a92d5b9dae90a534b42214f728422be2ab1 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Wed, 24 Aug 2016 12:59:57 +0800 Subject: [PATCH] config: set TMPDIR, TEMP and TMP to HOMEBREW_TEMP TMPDIR, TEMP and TMP (when set) are not whitelisted for writing in sandbox.rb, which could result in sandbox violations when programs attempt to write to these locations. Setting TMPDIR, TEMP and TMP to HOMEBREW_TEMP (which defaults to /tmp when not set) works around the aforementioned problem and also improves uniformity in the locations of tempfiles created during Homebrew operations. Caveat: Non-matching HOMEBREW_TEMP and TMPDIR could lead to undesirable side effects in certain cases, e.g., emacsclient not being able to find an existing server (whose socket lives in $TMPDIR/emacs$UID/) when launched through brew edit. --- Library/Homebrew/config.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index 70a2386a92..b16fb7a835 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -35,6 +35,11 @@ HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/") # Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets HOMEBREW_TEMP = Pathname.new(ENV.fetch("HOMEBREW_TEMP", "/tmp")) +# Set common tmpdir environment variables to HOMEBREW_TEMP +ENV["TMPDIR"] = HOMEBREW_TEMP +ENV["TEMP"] = HOMEBREW_TEMP +ENV["TMP"] = HOMEBREW_TEMP + unless defined? HOMEBREW_LIBRARY_PATH # Root of the Homebrew code base HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent