Skip to content

Commit 1b9d7f7

Browse files
feat: skip warning cli flag added (#55)
1 parent 0a85254 commit 1b9d7f7

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

analyzer/analyzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
type Analyzer interface {
1414
// Analyze analyzes the provided source code and returns any issues found.
1515
// TODO: better to update the code to take a reader interface instead of path
16-
Analyze(path string, withTrace bool) ([]*Issue, error)
16+
Analyze(path string, withTrace bool, skipWarnings bool) ([]*Issue, error)
1717

1818
// TraceStack generates callstack for a function to debug
1919
TraceStack(path string, function string) (*CallStack, error)

analyzer/opcode/opcode.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func NewAnalyser(profile *profile.VMProfile) analyzer.Analyzer {
2222
return &opcode{profile: profile}
2323
}
2424

25-
func (op *opcode) Analyze(path string, withTrace bool) ([]*analyzer.Issue, error) {
25+
func (op *opcode) Analyze(path string, withTrace bool, skipWarnings bool) ([]*analyzer.Issue, error) {
2626
callGraph, err := op.buildCallGraph(path)
2727
if err != nil {
2828
return nil, err
@@ -55,6 +55,9 @@ func (op *opcode) Analyze(path string, withTrace bool) ([]*analyzer.Issue, error
5555
),
5656
}
5757
if common.ShouldIgnoreSource(source, op.profile.IgnoredFunctions) {
58+
if skipWarnings {
59+
continue
60+
}
5861
opts = append(opts, analyzer.WithSeverity(analyzer.IssueSeverityWarning))
5962
}
6063
if !withTrace {

analyzer/syscall/asm_syscall.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewAssemblySyscallAnalyser(profile *profile.VMProfile) analyzer.Analyzer {
3232
// Analyze scans an assembly file for syscalls and detects compatibility issues.
3333
//
3434
//nolint:cyclop
35-
func (a *asmSyscallAnalyser) Analyze(path string, withTrace bool) ([]*analyzer.Issue, error) {
35+
func (a *asmSyscallAnalyser) Analyze(path string, withTrace bool, skipWarnings bool) ([]*analyzer.Issue, error) {
3636
callGraph, err := a.buildCallGraph(path)
3737
if err != nil {
3838
return nil, err
@@ -70,10 +70,16 @@ func (a *asmSyscallAnalyser) Analyze(path string, withTrace bool) ([]*analyzer.I
7070
for _, source := range sources {
7171
severity := analyzer.IssueSeverityCritical
7272
if common.ShouldIgnoreSource(source, a.profile.IgnoredFunctions) {
73+
if skipWarnings {
74+
continue
75+
}
7376
severity = analyzer.IssueSeverityWarning
7477
}
7578
message := fmt.Sprintf("Potential Incompatible Syscall Detected: %d", syscall.Number)
7679
if slices.Contains(a.profile.NOOPSyscalls, syscall.Number) {
80+
if skipWarnings {
81+
continue
82+
}
7783
message = fmt.Sprintf("Potential NOOP Syscall Detected: %d", syscall.Number)
7884
severity = analyzer.IssueSeverityWarning
7985
}

analyzer/syscall/go_syscall.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewGOSyscallAnalyser(profile *profile.VMProfile) analyzer.Analyzer {
4040
// Analyze scans a Go binary for syscalls and detects compatibility issues.
4141
//
4242
//nolint:cyclop
43-
func (a *goSyscallAnalyser) Analyze(path string, withTrace bool) ([]*analyzer.Issue, error) {
43+
func (a *goSyscallAnalyser) Analyze(path string, withTrace bool, skipWarnings bool) ([]*analyzer.Issue, error) {
4444
cg, fset, err := a.buildCallGraph(path)
4545
if err != nil {
4646
return nil, err
@@ -59,6 +59,9 @@ func (a *goSyscallAnalyser) Analyze(path string, withTrace bool) ([]*analyzer.Is
5959
severity := analyzer.IssueSeverityCritical
6060
message := fmt.Sprintf("Potential Incompatible Syscall Detected: %d", syscll.num)
6161
if slices.Contains(a.profile.NOOPSyscalls, syscll.num) {
62+
if skipWarnings {
63+
continue
64+
}
6265
severity = analyzer.IssueSeverityWarning
6366
message = fmt.Sprintf("Potential NOOP Syscall Detected: %d", syscll.num)
6467
}

cmd/analyze.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ var (
5454
Required: false,
5555
Value: false,
5656
}
57+
SkipWarnings = &cli.BoolFlag{
58+
Name: "skip-warnings",
59+
Usage: "skip the issue with severity warning",
60+
Required: false,
61+
Value: false,
62+
}
5763

5864
BaselineReport = &cli.StringFlag{
5965
Name: "baseline-report",
@@ -76,6 +82,7 @@ func CreateAnalyzeCommand(action cli.ActionFunc) *cli.Command {
7682
FormatFlag,
7783
ReportOutputPathFlag,
7884
TraceFlag,
85+
SkipWarnings,
7986
BaselineReport,
8087
},
8188
}
@@ -104,14 +111,15 @@ func AnalyzeCompatibility(ctx *cli.Context) error {
104111
reportOutputPath := ctx.Path(ReportOutputPathFlag.Name)
105112
analysisType := ctx.String(AnalysisTypeFlag.Name)
106113
withTrace := ctx.Bool(TraceFlag.Name)
114+
skipWarnings := ctx.Bool(SkipWarnings.Name)
107115
baselineReport := ctx.Path(BaselineReport.Name)
108116

109117
disassemblyPath, err = disassemble(vmProfile, source, disassemblyPath)
110118
if err != nil {
111119
return fmt.Errorf("error disassembling the file: %w", err)
112120
}
113121

114-
issues, err := analyze(vmProfile, disassemblyPath, analysisType, withTrace)
122+
issues, err := analyze(vmProfile, disassemblyPath, analysisType, withTrace, skipWarnings)
115123
if err != nil {
116124
return fmt.Errorf("analysis failed: %w", err)
117125
}
@@ -146,19 +154,19 @@ func disassemble(prof *profile.VMProfile, path, outputPath string) (string, erro
146154
}
147155

148156
// analyze runs the selected analyzer(s).
149-
func analyze(prof *profile.VMProfile, disassemblyPath, mode string, withTrace bool) ([]*analyzer.Issue, error) {
157+
func analyze(prof *profile.VMProfile, disassemblyPath, mode string, withTrace bool, skipWarnings bool) ([]*analyzer.Issue, error) {
150158
if mode == "opcode" {
151-
return opcode.NewAnalyser(prof).Analyze(disassemblyPath, withTrace)
159+
return opcode.NewAnalyser(prof).Analyze(disassemblyPath, withTrace, skipWarnings)
152160
}
153161
if mode == "syscall" {
154-
return syscall.NewAssemblySyscallAnalyser(prof).Analyze(disassemblyPath, withTrace)
162+
return syscall.NewAssemblySyscallAnalyser(prof).Analyze(disassemblyPath, withTrace, skipWarnings)
155163
}
156164
// by default analyze both
157-
opIssues, err := opcode.NewAnalyser(prof).Analyze(disassemblyPath, withTrace)
165+
opIssues, err := opcode.NewAnalyser(prof).Analyze(disassemblyPath, withTrace, skipWarnings)
158166
if err != nil {
159167
return nil, err
160168
}
161-
sysIssues, err := syscall.NewAssemblySyscallAnalyser(prof).Analyze(disassemblyPath, withTrace)
169+
sysIssues, err := syscall.NewAssemblySyscallAnalyser(prof).Analyze(disassemblyPath, withTrace, skipWarnings)
162170
if err != nil {
163171
return nil, err
164172
}

0 commit comments

Comments
 (0)