From 731a805a9ec384a0d6bc983ff532e285be259be6 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Thu, 9 Feb 2023 12:42:06 -0800 Subject: [PATCH] getBinaryDeps: properly handle circular lib dependencies This moves the recursive bit outside of getBinaryDeps and properly handles circular dependencies. --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index bce5c36..bafa4bb 100644 --- a/main.go +++ b/main.go @@ -177,8 +177,11 @@ func getHookFiles(filesdir string) (files []string, err error) { return files, nil } +func getDeps(file string, parents map[string]struct{}) (files []string, err error) { -func getDeps(file string) (files []string, err error) { + if _, found := parents[file]; found { + return + } // get dependencies for binaries fd, err := elf.Open(file) @@ -188,6 +191,7 @@ func getDeps(file string) (files []string, err error) { libs, _ := fd.ImportedLibraries() fd.Close() files = append(files, file) + parents[file] = struct{}{} if len(libs) == 0 { return @@ -208,7 +212,7 @@ func getDeps(file string) (files []string, err error) { for _, libdir := range libdirs { path := filepath.Join(libdir, lib) if _, err := os.Stat(path); err == nil { - binaryDepFiles, err := getDeps(path) + binaryDepFiles, err := getDeps(path, parents) if err != nil { return nil, err }