From b9d64fed4de6500e376e58a36596f9dffb22224b Mon Sep 17 00:00:00 2001 From: Nanda H Krishna Date: Mon, 14 Jun 2021 17:47:16 +0530 Subject: [PATCH 1/2] formula_installer: restrict use of Formula from Keg --- Library/Homebrew/formula_installer.rb | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index f13b557d70..8775a4a2c7 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1076,10 +1076,30 @@ class FormulaInstaller #{HOMEBREW_LIBRARY_PATH}/postinstall.rb ] - args << if formula.local_bottle_path.present? - formula.prefix/".brew/#{formula.name}.rb" - else - formula.path + keg_formula_path = formula.opt_prefix/".brew/#{formula.name}.rb" + tap_formula_path = formula.path + + # Use the formula from the keg if: + # * Installing from a local bottle, or + # * The formula doesn't exist in the tap (or the tap isn't installed), or + # * The formula in the tap has a different pkg_version. + # In all other cases, including if the formula from the keg is unreadable + # (third-party taps may `require` some of their own libraries), use the + # formula from the tap. + args << begin + keg_formula = Formulary.factory(keg_formula_path) + tap_formula = Formulary.factory(tap_formula_path) if tap_formula_path.exist? + other_version_installed = (keg_formula.pkg_version != tap_formula&.pkg_version) + + if formula.local_bottle_path.present? || + !tap_formula_path.exist? || + other_version_installed + keg_formula_path + else + tap_formula_path + end + rescue FormulaUnreadableError + tap_formula_path end Utils.safe_fork do From c70bcd53f70ad5010e64aae541830f040be2535c Mon Sep 17 00:00:00 2001 From: Nanda H Krishna Date: Tue, 15 Jun 2021 17:30:38 +0530 Subject: [PATCH 2/2] formula_installer: minor refactoring --- Library/Homebrew/formula_installer.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 8775a4a2c7..8b0ab569d0 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1076,9 +1076,6 @@ class FormulaInstaller #{HOMEBREW_LIBRARY_PATH}/postinstall.rb ] - keg_formula_path = formula.opt_prefix/".brew/#{formula.name}.rb" - tap_formula_path = formula.path - # Use the formula from the keg if: # * Installing from a local bottle, or # * The formula doesn't exist in the tap (or the tap isn't installed), or @@ -1086,7 +1083,9 @@ class FormulaInstaller # In all other cases, including if the formula from the keg is unreadable # (third-party taps may `require` some of their own libraries), use the # formula from the tap. - args << begin + formula_path = begin + keg_formula_path = formula.opt_prefix/".brew/#{formula.name}.rb" + tap_formula_path = formula.path keg_formula = Formulary.factory(keg_formula_path) tap_formula = Formulary.factory(tap_formula_path) if tap_formula_path.exist? other_version_installed = (keg_formula.pkg_version != tap_formula&.pkg_version) @@ -1102,6 +1101,8 @@ class FormulaInstaller tap_formula_path end + args << formula_path + Utils.safe_fork do if Sandbox.available? sandbox = Sandbox.new