|
8 | 8 | "github.com/murphysecurity/murphysec/infra/logctx" |
9 | 9 | "github.com/murphysecurity/murphysec/model" |
10 | 10 | "github.com/murphysecurity/murphysec/scanerr" |
| 11 | + "os" |
11 | 12 | "os/exec" |
12 | 13 | "reflect" |
13 | 14 | "runtime" |
@@ -59,27 +60,30 @@ func inspectInstalledSoftware(ctx context.Context, module *model.Module) { |
59 | 60 | } |
60 | 61 | var foundCmd = false |
61 | 62 | for _, f := range scanFunc { |
62 | | - pkgs, e := f(ctx) |
63 | 63 | var fn = strings.TrimPrefix(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), "github.com/murphysecurity/murphysec/envinspection.") |
64 | | - if e == nil && len(pkgs) > 0 { |
65 | | - module.Dependencies = append(module.Dependencies, pkgs...) |
66 | | - LOG.Infof("inspection succeeded(%s), total %d items", fn, len(pkgs)) |
67 | | - continue |
68 | | - } else { |
| 64 | + pkgs, e := f(ctx) |
| 65 | + if e != nil { |
69 | 66 | LOG.Warnf("Software inspection error(%s): %s, ", fn, e) |
70 | | - } |
71 | | - foundCmd = true |
72 | | - var pError *exec.ExitError |
73 | | - if errors.As(e, &pError) { |
74 | | - var stderrText = strings.TrimSpace(string(pError.Stderr)) |
75 | | - if stderrText == "" { |
76 | | - stderrText = "(no stderr output)" |
| 67 | + var pError *exec.ExitError |
| 68 | + if errors.As(e, &pError) { |
| 69 | + var stderrText = strings.TrimSpace(string(pError.Stderr)) |
| 70 | + if stderrText == "" { |
| 71 | + stderrText = "(no stderr output)" |
| 72 | + } |
| 73 | + scanerr.Add(ctx, scanerr.Param{ |
| 74 | + Kind: "env_inspection_error", |
| 75 | + Content: string(pError.Stderr), |
| 76 | + }) |
| 77 | + continue |
| 78 | + } |
| 79 | + if os.IsNotExist(e) { |
| 80 | + continue |
77 | 81 | } |
78 | | - scanerr.Add(ctx, scanerr.Param{ |
79 | | - Kind: "env_inspection_error", |
80 | | - Content: string(pError.Stderr), |
81 | | - }) |
| 82 | + foundCmd = true |
| 83 | + continue |
82 | 84 | } |
| 85 | + module.Dependencies = append(module.Dependencies, pkgs...) |
| 86 | + foundCmd = true |
83 | 87 | } |
84 | 88 | if !foundCmd { |
85 | 89 | scanerr.Add(ctx, scanerr.Param{ |
|
0 commit comments