From 8a8ab8cb18161244ee6f078b43a89b3588d99a4d Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Fri, 11 Sep 2020 13:09:59 +0900 Subject: [PATCH] feat(libscan): enable to scan vulns of libs with pseudo #1035 (#1050) --- scan/base.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scan/base.go b/scan/base.go index 60f549ab..0b240b7a 100644 --- a/scan/base.go +++ b/scan/base.go @@ -4,6 +4,7 @@ import ( "bufio" "encoding/json" "fmt" + "io/ioutil" "net" "os" "regexp" @@ -562,12 +563,23 @@ func (l *base) scanLibraries() (err error) { if _, ok := libFilemap[path]; ok { continue } - cmd := fmt.Sprintf("cat %s", path) - r := exec(l.ServerInfo, cmd, noSudo) - if !r.isSuccess() { - return xerrors.Errorf("Failed to get target file: %s, filepath: %s", r, path) + + var bytes []byte + switch l.Distro.Family { + case config.ServerTypePseudo: + bytes, err = ioutil.ReadFile(path) + if err != nil { + return xerrors.Errorf("Failed to get target file: %s, filepath: %s", err, path) + } + default: + cmd := fmt.Sprintf("cat %s", path) + r := exec(l.ServerInfo, cmd, noSudo) + if !r.isSuccess() { + return xerrors.Errorf("Failed to get target file: %s, filepath: %s", r, path) + } + bytes = []byte(r.Stdout) } - libFilemap[path] = []byte(r.Stdout) + libFilemap[path] = bytes } for path, b := range libFilemap {