fix: panic scanning binaries without symtab (#2739)

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow 2024-03-27 13:51:45 -04:00 committed by GitHub
parent 469b4c13bb
commit 410867ca0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -57,6 +57,9 @@ func machoHasEntrypoint(f *macho.File) bool {
}
func machoHasExports(f *macho.File) bool {
if f == nil || f.Symtab == nil {
return false
}
for _, sym := range f.Symtab.Syms {
// look for symbols that are:
// - not private and are external

View File

@ -69,6 +69,11 @@ func Test_machoHasExports(t *testing.T) {
fixture: "bin/hello_mac",
want: false,
},
{
name: "gcc-amd64-darwin-exec-debug",
fixture: "bin/gcc-amd64-darwin-exec-debug",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View File

@ -1,10 +1,13 @@
# invoke all make files in subdirectories
.PHONY: all hello libhello
all: hello libhello
all: hello libhello ../bin/gcc-amd64-darwin-exec-debug
hello:
$(MAKE) -C hello
libhello:
$(MAKE) -C libhello
../bin/gcc-amd64-darwin-exec-debug:
curl -L -o ../bin/gcc-amd64-darwin-exec-debug https://github.com/golang/tools/raw/9ed98faabadd2cb94de86d5290b1c6942b7c4877/cmd/splitdwarf/internal/macho/testdata/gcc-amd64-darwin-exec-debug