diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-02-23 18:02:33 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-02-23 18:02:33 +0900 |
| commit | dccb3666080686da73159680590352c23cf69c4f (patch) | |
| tree | ce9b24b8e88e0bee67b14eeec043728b9fd5776b /ldd | |
| parent | 83c8f0488b168be5f374d3ad9eef58dde4d144ef (diff) | |
ldd: handle behaviour on static executable
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd')
| -rw-r--r-- | ldd/exec.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/ldd/exec.go b/ldd/exec.go index 06769373..4e5de479 100644 --- a/ldd/exec.go +++ b/ldd/exec.go @@ -1,10 +1,10 @@ package ldd import ( + "bytes" "context" "os" "os/exec" - "strings" "time" "git.gensokyo.uk/security/fortify/helper" @@ -13,6 +13,10 @@ import ( const lddTimeout = 2 * time.Second +var ( + msgStaticGlibc = []byte("not a dynamic executable") +) + func Exec(ctx context.Context, p string) ([]*Entry, error) { var h helper.Helper @@ -32,8 +36,8 @@ func Exec(ctx context.Context, p string) ([]*Entry, error) { return nil, err } - stdout := new(strings.Builder) - h.Stdout(stdout).Stderr(os.Stderr) + stdout, stderr := new(bytes.Buffer), new(bytes.Buffer) + h.Stdout(stdout).Stderr(stderr) c, cancel := context.WithTimeout(ctx, lddTimeout) defer cancel() @@ -41,6 +45,12 @@ func Exec(ctx context.Context, p string) ([]*Entry, error) { return nil, err } if err := h.Wait(); err != nil { + m := stderr.Bytes() + if bytes.Contains(m, msgStaticGlibc) { + return nil, nil + } + + _, _ = os.Stderr.Write(m) return nil, err } |
