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

os/linux/ld: harden brewed_ld_so_diagnostics against TypeError #18333

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Library/Homebrew/os/linux/ld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
module Ld
sig { returns(String) }
def self.brewed_ld_so_diagnostics
@brewed_ld_so_diagnostics ||= T.let({}, T.nilable(T::Hash[Pathname, String]))

Check warning on line 10 in Library/Homebrew/os/linux/ld.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/linux/ld.rb#L10

Added line #L10 was not covered by tests

brewed_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
return "" unless brewed_ld_so.exist?

ld_so_output = Utils.popen_read(brewed_ld_so, "--list-diagnostics")
return "" unless $CHILD_STATUS.success?
brewed_ld_so_target = brewed_ld_so.readlink
@brewed_ld_so_diagnostics[brewed_ld_so_target] ||= begin
ld_so_output = Utils.popen_read(brewed_ld_so, "--list-diagnostics")
ld_so_output if $CHILD_STATUS.success?
end

Check warning on line 19 in Library/Homebrew/os/linux/ld.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/linux/ld.rb#L15-L19

Added lines #L15 - L19 were not covered by tests

ld_so_output
@brewed_ld_so_diagnostics[brewed_ld_so_target].to_s

Check warning on line 21 in Library/Homebrew/os/linux/ld.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/linux/ld.rb#L21

Added line #L21 was not covered by tests
end

sig { returns(String) }
Expand Down