@@ -17,15 +17,18 @@ import (
17
17
"golang.org/x/exp/slices"
18
18
"golang.org/x/vulndb/cmd/vulnreport/log"
19
19
"golang.org/x/vulndb/internal/osvutils"
20
+ "golang.org/x/vulndb/internal/pkgsite"
20
21
"golang.org/x/vulndb/internal/report"
21
22
"golang.org/x/vulndb/internal/symbols"
22
23
)
23
24
24
25
var (
25
- force = flag .Bool ("f" , false , "for fix, force Fix to run even if there are no lint errors" )
26
- skipChecks = flag .Bool ("skip-checks" , false , "for fix, skip all checks except lint" )
27
- skipAlias = flag .Bool ("skip-alias" , false , "for fix, skip adding new GHSAs and CVEs" )
28
- skipSymbols = flag .Bool ("skip-symbols" , false , "for lint and fix, don't load package for symbols checks" )
26
+ force = flag .Bool ("f" , false , "for fix, force Fix to run even if there are no lint errors" )
27
+ skipChecks = flag .Bool ("skip-checks" , false , "for fix, skip all checks except lint" )
28
+ skipAlias = flag .Bool ("skip-alias" , false , "for fix, skip adding new GHSAs and CVEs" )
29
+ skipSymbols = flag .Bool ("skip-symbols" , false , "for fix, don't load package for symbols checks" )
30
+ skipPackages = flag .Bool ("skip-packages" , false , "for fix, don't check if packages exist" )
31
+ skipRefs = flag .Bool ("skip-refs" , false , "for fix, don't check if references exist" )
29
32
)
30
33
31
34
type fix struct {
@@ -58,9 +61,12 @@ type fixer struct {
58
61
* linter
59
62
* aliasFinder
60
63
* fileWriter
64
+
65
+ pkc * pkgsite.Client
61
66
}
62
67
63
68
func (f * fixer ) setup (ctx context.Context , env environment ) error {
69
+ f .pkc = env .PkgsiteClient ()
64
70
f .linter = new (linter )
65
71
f .aliasFinder = new (aliasFinder )
66
72
f .fileWriter = new (fileWriter )
@@ -85,8 +91,8 @@ func (f *fixer) fixAndWriteAll(ctx context.Context, r *yamlReport, addNotes bool
85
91
func (f * fixer ) fix (ctx context.Context , r * yamlReport , addNotes bool ) (fixed bool ) {
86
92
fixed = true
87
93
88
- if lints := r .Lint (f .pc ); * force || len (lints ) > 0 {
89
- r .Fix (f .pc )
94
+ if lints := r .Lint (f .pxc ); * force || len (lints ) > 0 {
95
+ r .Fix (f .pxc )
90
96
}
91
97
92
98
if ! * skipChecks {
@@ -97,12 +103,12 @@ func (f *fixer) fix(ctx context.Context, r *yamlReport, addNotes bool) (fixed bo
97
103
98
104
// Check for remaining lint errors.
99
105
if addNotes {
100
- if r .LintAsNotes (f .pc ) {
106
+ if r .LintAsNotes (f .pxc ) {
101
107
log .Warnf ("%s: still has lint errors after fix" , r .ID )
102
108
fixed = false
103
109
}
104
110
} else {
105
- if lints := r .Lint (f .pc ); len (lints ) > 0 {
111
+ if lints := r .Lint (f .pxc ); len (lints ) > 0 {
106
112
log .Warnf ("%s: still has lint errors after fix:\n \t - %s" , r .ID , strings .Join (lints , "\n \t - " ))
107
113
fixed = false
108
114
}
@@ -124,10 +130,17 @@ func (f *fixer) allChecks(ctx context.Context, r *yamlReport, addNotes bool) (ok
124
130
ok = false
125
131
}
126
132
133
+ if ! * skipPackages {
134
+ log .Infof ("%s: checking that all packages exist" , r .ID )
135
+ if err := r .CheckPackages (ctx , f .pkc ); err != nil {
136
+ fixErr ("package error: %s" , err )
137
+ }
138
+ }
139
+
127
140
if ! * skipSymbols {
128
- log .Infof ("%s: checking packages and symbols (use -skip-symbols to skip this)" , r .ID )
141
+ log .Infof ("%s: checking symbols (use -skip-symbols to skip this)" , r .ID )
129
142
if err := r .checkSymbols (); err != nil {
130
- fixErr ("package or symbol error: %s" , err )
143
+ fixErr ("symbol error: %s" , err )
131
144
}
132
145
}
133
146
@@ -138,9 +151,11 @@ func (f *fixer) allChecks(ctx context.Context, r *yamlReport, addNotes bool) (ok
138
151
}
139
152
}
140
153
141
- // For now, this is a fix check instead of a lint.
142
- log .Infof ("%s: checking that all references are reachable" , r .ID )
143
- checkRefs (r .References , fixErr )
154
+ if ! * skipRefs {
155
+ // For now, this is a fix check instead of a lint.
156
+ log .Infof ("%s: checking that all references are reachable" , r .ID )
157
+ checkRefs (r .References , fixErr )
158
+ }
144
159
145
160
return ok
146
161
}
@@ -171,7 +186,16 @@ func (r *yamlReport) checkSymbols() error {
171
186
log .Infof ("%s: excluded, skipping symbol checks" , r .ID )
172
187
return nil
173
188
}
189
+ if len (r .Modules ) == 0 {
190
+ log .Infof ("%s: no modules, skipping symbol checks" , r .ID )
191
+ return nil
192
+ }
174
193
for _ , m := range r .Modules {
194
+ if len (m .Packages ) == 0 {
195
+ log .Infof ("%s: module %s has no packages, skipping symbol checks" , r .ID , m .Module )
196
+ return nil
197
+ }
198
+
175
199
if m .IsFirstParty () {
176
200
gover := runtime .Version ()
177
201
ver := semverForGoVersion (gover )
@@ -196,8 +220,16 @@ func (r *yamlReport) checkSymbols() error {
196
220
}
197
221
198
222
for _ , p := range m .Packages {
199
- if p .SkipFix != "" {
200
- log .Infof ("%s: skipping symbol checks for package %s (reason: %q)" , r .ID , p .Package , p .SkipFix )
223
+ if len (p .AllSymbols ()) == 0 && p .SkipFixSymbols != "" {
224
+ log .Warnf ("%s: skip_fix not needed" , r .Filename )
225
+ continue
226
+ }
227
+ if len (p .AllSymbols ()) == 0 {
228
+ log .Infof ("%s: skipping symbol checks for package %s (no symbols)" , r .ID , p .Package )
229
+ continue
230
+ }
231
+ if p .SkipFixSymbols != "" {
232
+ log .Infof ("%s: skipping symbol checks for package %s (reason: %q)" , r .ID , p .Package , p .SkipFixSymbols )
201
233
continue
202
234
}
203
235
syms , err := symbols .Exported (m , p )
0 commit comments