From 5c068ef82cfb3344f10d7ab3c42003069dd000bb Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Fri, 8 Feb 2019 20:44:50 +0100 Subject: [PATCH] elf.rb: avoid corrupted elf files Some elf files like unittest files or memory dumps may not be completely readable by readelf. Readelf will fail after the following message: readelf: Warning: possibly corrupt ELF header - it has a non-zero program header offset, but no program headers This patches avoid these files when there is a non zero offset but no program headers --- Library/Homebrew/os/linux/elf.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/os/linux/elf.rb b/Library/Homebrew/os/linux/elf.rb index e73f8154a2..b7a1fcb72d 100644 --- a/Library/Homebrew/os/linux/elf.rb +++ b/Library/Homebrew/os/linux/elf.rb @@ -133,8 +133,10 @@ module ELFShim soname = nil needed = [] command = ["readelf", "-d", path.expand_path.to_s] - lines = Utils.safe_popen_read(*command).split("\n") + lines = Utils.popen_read(*command, err: :out).split("\n") lines.each do |s| + next if s.start_with?("readelf: Warning: possibly corrupt ELF header") + filename = s[/\[(.*)\]/, 1] next if filename.nil?