From 252e398b78448b4fb97649d7127388078235db9e Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sat, 8 Oct 2022 00:15:37 +0800 Subject: [PATCH 1/3] formula: ensure `rpath` is passed a valid `target` Setting `target` to a path outside `HOMEBREW_PREFIX` is not portable, and will be invalid for some Homebrew installations. If we want to add an `rpath` outside of `HOMEBREW_PREFIX`, we should just use the absolute path instead. See discussion at Homebrew/homebrew-core#110520. --- Library/Homebrew/formula.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index de6596ff15..24e4a1da11 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1615,6 +1615,10 @@ class Formula # sig { params(source: Pathname, target: Pathname).returns(String) } def rpath(source: bin, target: lib) + unless target.to_s.start_with?(HOMEBREW_PREFIX) + odie "`target` should only be used for paths inside HOMEBREW_PREFIX!" + end + "#{loader_path}/#{target.relative_path_from(source)}" end From 4c2d903738a92eb34e5ca54d2d64768500677ffc Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sat, 8 Oct 2022 00:25:38 +0800 Subject: [PATCH 2/3] `raise` instead of `odie` Change based on review comments. --- Library/Homebrew/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 24e4a1da11..3e8aed8e4d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1616,7 +1616,7 @@ class Formula sig { params(source: Pathname, target: Pathname).returns(String) } def rpath(source: bin, target: lib) unless target.to_s.start_with?(HOMEBREW_PREFIX) - odie "`target` should only be used for paths inside HOMEBREW_PREFIX!" + raise "`target` should only be used for paths inside HOMEBREW_PREFIX!" end "#{loader_path}/#{target.relative_path_from(source)}" From 933129dcdba6f7707c04905ebf13591d7bf8c055 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:43:43 +0800 Subject: [PATCH 3/3] Make error message clearer Co-authored-by: Bo Anderson --- Library/Homebrew/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3e8aed8e4d..006bc36ddf 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1616,7 +1616,7 @@ class Formula sig { params(source: Pathname, target: Pathname).returns(String) } def rpath(source: bin, target: lib) unless target.to_s.start_with?(HOMEBREW_PREFIX) - raise "`target` should only be used for paths inside HOMEBREW_PREFIX!" + raise "rpath `target` should only be used for paths inside HOMEBREW_PREFIX!" end "#{loader_path}/#{target.relative_path_from(source)}"