Skip to content

Commit abd9847

Browse files
committed
Refuse to update old databases
Very old databases can causes 1000+ changes due getting very CVE updated. For very old database is is better to download the latest new archive.
1 parent f36bebf commit abd9847

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

cmd/cvetool/update.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
ds_sqlite "github.com/ComplianceAsCode/cvetool/datastore/sqlite"
1111
"github.com/quay/claircore/libvuln"
12+
"github.com/quay/claircore/libvuln/driver"
1213
_ "github.com/quay/claircore/updater/defaults"
1314
"github.com/urfave/cli/v2"
1415
)
@@ -66,6 +67,32 @@ func update(c *cli.Context) error {
6667
UpdaterSets: []string{"rhel-vex", "clair.cvss"},
6768
}
6869

70+
// Check last update time
71+
updateOps, err := matcherStore.GetUpdateOperations(ctx, driver.VulnerabilityKind)
72+
if err != nil {
73+
return fmt.Errorf("error getting update operations: %v", err)
74+
}
75+
76+
// Find the most recent update time across all updaters
77+
var lastUpdate time.Time
78+
for _, ops := range updateOps {
79+
if len(ops) > 0 {
80+
// ops are sorted by date descending, so first element is most recent
81+
if ops[0].Date.After(lastUpdate) {
82+
lastUpdate = ops[0].Date
83+
}
84+
}
85+
}
86+
87+
if !lastUpdate.IsZero() {
88+
fmt.Printf("Last update: %s (%s ago)\n", lastUpdate.Format(time.RFC1123), time.Since(lastUpdate).Round(time.Second))
89+
if time.Since(lastUpdate) > (24 * time.Hour * 30) {
90+
return fmt.Errorf("Database more than 30 days old, refusing to update. Delete the database and run this commmand again.")
91+
}
92+
} else {
93+
fmt.Println("No previous updates found in database")
94+
}
95+
6996
lv, err := libvuln.New(ctx, matcherOpts)
7097
if err != nil {
7198
return fmt.Errorf("error creating Libvuln: %v", err)

0 commit comments

Comments
 (0)