Skip to content

Commit 1abe368

Browse files
authored
fix: Debian-CVE with no fixed not being converted (and added dryrun mode) (#4033)
1 parent d94f477 commit 1abe368

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

vulnfeeds/cmd/debian/main.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func main() {
4444
debianOutputPath := flag.String("output_path", debianOutputPathDefault, "Path to output OSV files.")
4545
outputBucketName := flag.String("output_bucket", outputBucketDefault, "The GCS bucket to write to.")
4646
numWorkers := flag.Int("num_workers", 64, "Number of workers to process records")
47+
uploadToGCS := flag.Bool("uploadToGCS", false, "If true, do not write to GCS bucket and instead write to local disk.")
4748
flag.Parse()
4849

4950
err := os.MkdirAll(*debianOutputPath, 0755)
@@ -64,11 +65,14 @@ func main() {
6465
allCVEs := vulns.LoadAllCVEs(defaultCvePath)
6566

6667
ctx := context.Background()
67-
storageClient, err := storage.NewClient(ctx)
68-
if err != nil {
69-
logger.Fatal("Failed to create storage client", slog.Any("err", err))
68+
var bkt *storage.BucketHandle
69+
if *uploadToGCS {
70+
storageClient, err := storage.NewClient(ctx)
71+
if err != nil {
72+
logger.Fatal("Failed to create storage client", slog.Any("err", err))
73+
}
74+
bkt = storageClient.Bucket(*outputBucketName)
7075
}
71-
bkt := storageClient.Bucket(*outputBucketName)
7276

7377
var wg sync.WaitGroup
7478
vulnChan := make(chan *vulns.Vulnerability)
@@ -97,6 +101,7 @@ func main() {
97101
}
98102

99103
func worker(ctx context.Context, vulnChan <-chan *vulns.Vulnerability, bkt *storage.BucketHandle, outputDir string) {
104+
noUpload := bkt == nil
100105
for v := range vulnChan {
101106
debianID := v.ID
102107
if len(v.Affected) == 0 {
@@ -111,10 +116,26 @@ func worker(ctx context.Context, vulnChan <-chan *vulns.Vulnerability, bkt *stor
111116
continue
112117
}
113118

119+
objName := path.Join(outputDir, debianID+".json")
120+
121+
if noUpload {
122+
logger.Info("Writing to local disk", slog.String("path", objName))
123+
v.Modified = time.Now().UTC()
124+
buf, err = json.MarshalIndent(v, "", " ")
125+
if err != nil {
126+
logger.Error("failed to marshal vulnerability with modified time", slog.String("id", debianID), slog.Any("err", err))
127+
continue
128+
}
129+
if err := os.WriteFile(objName, buf, 0600); err != nil {
130+
logger.Error("failed to write file in dry run", slog.String("path", objName), slog.Any("err", err))
131+
}
132+
133+
continue
134+
}
135+
114136
hash := sha256.Sum256(buf)
115137
hexHash := hex.EncodeToString(hash[:])
116138

117-
objName := path.Join(outputDir, debianID+".json")
118139
obj := bkt.Object(objName)
119140

120141
// Check if object exists and if hash matches.
@@ -237,7 +258,9 @@ func generateOSVFromDebianTracker(debianData DebianSecurityTrackerData, debianRe
237258
}
238259

239260
if release.Status == "resolved" {
240-
pkgInfo.VersionInfo.AffectedVersions = []models.AffectedVersion{{Fixed: release.FixedVersion}}
261+
pkgInfo.VersionInfo.AffectedVersions = []models.AffectedVersion{{Introduced: "0"}, {Fixed: release.FixedVersion}}
262+
} else {
263+
pkgInfo.VersionInfo.AffectedVersions = []models.AffectedVersion{{Introduced: "0"}}
241264
}
242265

243266
if len(pkgInfo.VersionInfo.AffectedVersions) > 0 {

vulnfeeds/cmd/debian/main_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ func TestGenerateOSVFromDebianTracker(t *testing.T) {
102102
Published: now,
103103
Details: "In all versions of AppArmor mount rules are accidentally widened when compiled.",
104104
Affected: []osvschema.Affected{
105+
{
106+
Package: osvschema.Package{Ecosystem: "Debian:10", Name: "apparmor"},
107+
Ranges: []osvschema.Range{{Type: "ECOSYSTEM", Events: []osvschema.Event{{Introduced: "0"}}}},
108+
EcosystemSpecific: map[string]any{"urgency": string("unimportant")},
109+
},
110+
{
111+
Package: osvschema.Package{Ecosystem: "Debian:11", Name: "apparmor"},
112+
Ranges: []osvschema.Range{{Type: "ECOSYSTEM", Events: []osvschema.Event{{Introduced: "0"}}}},
113+
EcosystemSpecific: map[string]any{"urgency": string("unimportant")},
114+
},
115+
{
116+
Package: osvschema.Package{Ecosystem: "Debian:12", Name: "apparmor"},
117+
Ranges: []osvschema.Range{{Type: "ECOSYSTEM", Events: []osvschema.Event{{Introduced: "0"}}}},
118+
EcosystemSpecific: map[string]any{"urgency": string("unimportant")},
119+
},
105120
{
106121
Package: osvschema.Package{Name: "apparmor", Ecosystem: "Debian:13"},
107122
Ranges: []osvschema.Range{{Type: "ECOSYSTEM", Events: []osvschema.Event{{Introduced: "0"}, {Fixed: "3.0.12-1"}}}},

0 commit comments

Comments
 (0)