@@ -19,6 +19,7 @@ import (
19
19
"strings"
20
20
21
21
"golang.org/x/vulndb/internal"
22
+ "golang.org/x/vulndb/internal/cveschema5"
22
23
"golang.org/x/vulndb/internal/ghsa"
23
24
"golang.org/x/vulndb/internal/gitrepo"
24
25
"golang.org/x/vulndb/internal/issues"
35
36
func main () {
36
37
ctx := context .Background ()
37
38
flag .Usage = func () {
38
- fmt .Fprintf (flag .CommandLine .Output (), "usage: issue [cmd] [filename]\n " )
39
- fmt .Fprintf (flag .CommandLine .Output (), " triage: [filename]\n " )
40
- fmt .Fprintf (flag .CommandLine .Output (), " excluded: [filename]\n " )
39
+ fmt .Fprintf (flag .CommandLine .Output (), "usage: issue [cmd] [filename | cves]\n " )
40
+ fmt .Fprintf (flag .CommandLine .Output (), " triage [filename]: create issues to triage on the tracker for the aliases listed in the file\n " )
41
+ fmt .Fprintf (flag .CommandLine .Output (), " excluded [filename]: create excluded issues on the tracker for the aliases listed in the file\n " )
42
+ fmt .Fprintf (flag .CommandLine .Output (), " placeholder [cve(s)]: create a placeholder issue on the tracker for the given CVE(s)\n " )
43
+ fmt .Fprintf (flag .CommandLine .Output (), "\n " )
44
+ fmt .Fprintf (flag .CommandLine .Output (), "Flags:\n " )
41
45
flag .PrintDefaults ()
42
46
}
43
47
flag .Parse ()
@@ -59,6 +63,8 @@ func main() {
59
63
err = createIssueToTriage (ctx , c , ghsaClient , pc , filename )
60
64
case "excluded" :
61
65
err = createExcluded (ctx , c , ghsaClient , pc , filename )
66
+ case "placeholder" :
67
+ err = createPlaceholder (ctx , c , flag .Args ()[1 :])
62
68
default :
63
69
err = fmt .Errorf ("unsupported command: %q" , cmd )
64
70
}
@@ -93,6 +99,21 @@ func createExcluded(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Clie
93
99
return nil
94
100
}
95
101
102
+ func createPlaceholder (ctx context.Context , c * issues.Client , args []string ) error {
103
+ for _ , arg := range args {
104
+ if ! cveschema5 .IsCVE (arg ) {
105
+ return fmt .Errorf ("%q is not a CVE" , arg )
106
+ }
107
+ aliases := []string {arg }
108
+ packages := []string {"<placeholder>" }
109
+ bodies := []string {fmt .Sprintf ("This is a placeholder issue for %q." , arg )}
110
+ if err := publishIssue (ctx , c , packages , aliases , bodies , []string {}); err != nil {
111
+ return err
112
+ }
113
+ }
114
+ return nil
115
+ }
116
+
96
117
func constructIssue (ctx context.Context , c * issues.Client , ghsaClient * ghsa.Client , pc * proxy.Client , alias string , labels []string ) (err error ) {
97
118
var ghsas []* ghsa.SecurityAdvisory
98
119
if strings .HasPrefix (alias , "GHSA" ) {
@@ -143,17 +164,22 @@ func constructIssue(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Clie
143
164
}
144
165
bodies = append (bodies , body )
145
166
}
146
- sort .Strings (ids )
167
+ return publishIssue (ctx , c , []string {pkgPath }, ids , bodies , labels )
168
+ }
169
+
170
+ func publishIssue (ctx context.Context , c * issues.Client , packages , aliases , bodies , labels []string ) error {
171
+ sort .Strings (aliases )
147
172
iss := & issues.Issue {
148
- Title : fmt .Sprintf ("x/vulndb: potential Go vuln in %s: %s" , pkgPath , strings .Join (ids , ", " )),
173
+ Title : fmt .Sprintf ("x/vulndb: potential Go vuln in %s: %s" , strings .Join (packages , ", " ),
174
+ strings .Join (aliases , ", " )),
149
175
Body : strings .Join (bodies , "\n \n ----------\n \n " ),
150
176
Labels : labels ,
151
177
}
152
178
issNum , err := c .CreateIssue (ctx , iss )
153
179
if err != nil {
154
180
return err
155
181
}
156
- fmt .Printf ("created https://github.com/golang/vulndb/ issues/%d (%s)\n " , issNum , strings .Join (ids , ", " ))
182
+ fmt .Printf ("published issue https://%s/ issues/%d (%s)\n " , * issueRepo , issNum , strings .Join (aliases , ", " ))
157
183
return nil
158
184
}
159
185
0 commit comments