Skip to content

Commit ff566fe

Browse files
committed
internal/govulncheck: add Legacy prefix to legacy structs
We plan to replace structs with a new API design in a follow up CL. Prefix the legacy structs with Legacy as a first step for this transition, to make renaming easier. Also rename run.go to legacy_run.go, since the current implementation of Run will be replaced by Source and Binary. For golang/go#56042 Change-Id: I2fc80048bd937ad81ee1263aaac83495ea2e0876 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/443070 Run-TryBot: Julie Qiu <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]> Reviewed-by: Zvonimir Pavlinovic <[email protected]> Reviewed-by: Julie Qiu <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent a769f88 commit ff566fe

File tree

6 files changed

+34
-34
lines changed

6 files changed

+34
-34
lines changed

cmd/govulncheck/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ For details, see https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck.
7676
}
7777

7878
ctx := context.Background()
79-
_, err := govulncheck.Run(ctx, govulncheck.Config{
79+
_, err := govulncheck.LegacyRun(ctx, govulncheck.LegacyConfig{
8080
AnalysisType: mode,
8181
OutputType: outputType,
8282
Patterns: patterns,

exp/govulncheck/govulncheck.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
)
1313

1414
// Config is the configuration for Main.
15-
type Config = govulncheck.Config
15+
type Config = govulncheck.LegacyConfig
1616

1717
// Main is the main function for the govulncheck command line tool.
1818
func Main(cfg Config) error {
1919
ctx := context.Background()
20-
_, err := govulncheck.Run(ctx, cfg)
20+
_, err := govulncheck.LegacyRun(ctx, cfg)
2121
return err
2222
}

internal/govulncheck/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const (
3737
vulndbHost = "https://vuln.go.dev"
3838
)
3939

40-
// Config is the configuration for Main.
41-
type Config struct {
40+
// LegacyConfig is the configuration for Main.
41+
type LegacyConfig struct {
4242
// AnalysisType specifies the vulncheck analysis type.
4343
AnalysisType string
4444

internal/govulncheck/run.go renamed to internal/govulncheck/legacy_run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"golang.org/x/vuln/vulncheck"
2121
)
2222

23-
// Run is the main function for the govulncheck command line tool.
24-
func Run(ctx context.Context, cfg Config) (*Result, error) {
23+
// LegacyRun is the main function for the govulncheck command line tool.
24+
func LegacyRun(ctx context.Context, cfg LegacyConfig) (*Result, error) {
2525
dbs := []string{vulndbHost}
2626
if db := os.Getenv(envGOVULNDB); db != "" {
2727
dbs = strings.Split(db, ",")

internal/govulncheck/source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (e *PackageError) Error() string {
3131
// the cfg mode flags that vulncheck needs for analysis.
3232
// If the packages contain errors, a PackageError is returned containing a list of the errors,
3333
// along with the packages themselves.
34-
func loadPackages(cfg Config) ([]*vulncheck.Package, error) {
34+
func loadPackages(cfg LegacyConfig) ([]*vulncheck.Package, error) {
3535
patterns := cfg.Patterns
3636
cfg.SourceLoadConfig.Mode |= packages.NeedName | packages.NeedImports | packages.NeedTypes |
3737
packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedDeps |

internal/govulncheck/summary.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import (
99
"golang.org/x/vuln/vulncheck"
1010
)
1111

12-
// Summary is the govulncheck result.
12+
// LegacySummary is the govulncheck result.
1313
//
14-
// TODO(https://go.dev/issue/56042): replace Summary with Result
15-
type Summary struct {
14+
// TODO(https://go.dev/issue/56042): replace LegacySummary with Result
15+
type LegacySummary struct {
1616
// Vulnerabilities affecting the analysis target binary or source code.
17-
Affecting []Vuln
17+
Affecting []LegacyVuln
1818
// Vulnerabilities that may be imported but the vulnerable symbols are
1919
// not called. For binary analysis, this will be always empty.
20-
NonAffecting []Vuln
20+
NonAffecting []LegacyVuln
2121
}
2222

23-
// Vuln represents a vulnerability relevant to a (module, package).
24-
type Vuln struct {
23+
// LegacyVuln represents a vulnerability relevant to a (module, package).
24+
type LegacyVuln struct {
2525
OSV *osv.Entry
2626
PkgPath string // Package path.
2727
ModPath string // Module path.
@@ -30,33 +30,33 @@ type Vuln struct {
3030
// Trace contains a call stack for each affecting symbol.
3131
// For vulnerabilities found from binary analysis, and vulnerabilities
3232
// that are reported as Unaffecting ones, this will be always empty.
33-
Trace []Trace
33+
Trace []LegacyTrace
3434
}
3535

36-
// Trace represents a sample trace for a vulnerable symbol.
37-
type Trace struct {
38-
Symbol string // Name of the detected vulnerable function or method.
39-
Desc string // One-line description of the callstack.
40-
Stack []StackEntry // Call stack.
41-
Seen int // Number of similar call stacks.
36+
// LegacyTrace represents a sample trace for a vulnerable symbol.
37+
type LegacyTrace struct {
38+
Symbol string // Name of the detected vulnerable function or method.
39+
Desc string // One-line description of the callstack.
40+
Stack []LegacyStackEntry // Call stack.
41+
Seen int // Number of similar call stacks.
4242
}
4343

44-
// StackEntry represents a call stack entry.
45-
type StackEntry struct {
44+
// LegacyStackEntry represents a call stack entry.
45+
type LegacyStackEntry struct {
4646
FuncName string // Function name is the function name, adjusted to remove pointer annotation.
4747
CallSite string // Position of the call/reference site. It is one of the formats token.Pos.String() returns or empty if unknown.
4848
}
4949

5050
// summary summarize the analysis result.
51-
func summary(ci *callInfo, unaffected []*vulncheck.Vuln) Summary {
52-
var affecting, unaffecting []Vuln
51+
func summary(ci *callInfo, unaffected []*vulncheck.Vuln) LegacySummary {
52+
var affecting, unaffecting []LegacyVuln
5353
for _, vg := range ci.vulnGroups {
5454
// All the vulns in vg have the same PkgPath, ModPath and OSV.
5555
// All have a non-zero CallSink.
5656
v0 := vg[0]
5757
stacks := summarizeCallStacks(vg, ci)
5858

59-
affecting = append(affecting, Vuln{
59+
affecting = append(affecting, LegacyVuln{
6060
OSV: vg[0].OSV,
6161
PkgPath: v0.PkgPath,
6262
ModPath: v0.ModPath,
@@ -66,36 +66,36 @@ func summary(ci *callInfo, unaffected []*vulncheck.Vuln) Summary {
6666
})
6767
}
6868
for _, vuln := range unaffected {
69-
unaffecting = append(unaffecting, Vuln{
69+
unaffecting = append(unaffecting, LegacyVuln{
7070
OSV: vuln.OSV,
7171
PkgPath: vuln.PkgPath,
7272
ModPath: vuln.ModPath,
7373
FoundIn: foundVersion(vuln.ModPath, ci),
7474
FixedIn: fixedVersion(vuln.ModPath, vuln.OSV.Affected),
7575
})
7676
}
77-
return Summary{
77+
return LegacySummary{
7878
Affecting: affecting,
7979
NonAffecting: unaffecting,
8080
}
8181
}
8282

83-
func summarizeCallStacks(vg []*vulncheck.Vuln, ci *callInfo) []Trace {
84-
cs := make([]Trace, 0, len(vg))
83+
func summarizeCallStacks(vg []*vulncheck.Vuln, ci *callInfo) []LegacyTrace {
84+
cs := make([]LegacyTrace, 0, len(vg))
8585
// report one full call stack for each vuln.
8686
for _, v := range vg {
8787
css := ci.callStacks[v]
8888
if len(css) == 0 {
8989
continue
9090
}
91-
stack := make([]StackEntry, 0, len(css))
91+
stack := make([]LegacyStackEntry, 0, len(css))
9292
for _, e := range css[0] {
93-
stack = append(stack, StackEntry{
93+
stack = append(stack, LegacyStackEntry{
9494
FuncName: FuncName(e.Function),
9595
CallSite: FuncPos(e.Call),
9696
})
9797
}
98-
cs = append(cs, Trace{
98+
cs = append(cs, LegacyTrace{
9999
Symbol: v.Symbol,
100100
Desc: SummarizeCallStack(css[0], ci.topPackages, v.PkgPath),
101101
Stack: stack,

0 commit comments

Comments
 (0)