Skip to content

Commit

Permalink
fix: include CVEs prior to 2002
Browse files Browse the repository at this point in the history
resolves #265
  • Loading branch information
jeremylong committed Feb 11, 2025
1 parent a7efe2e commit 4eced1d
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ private Integer processRequest(NvdCveClientBuilder apiBuilder, CacheProperties p
// will hold all entries that have been changed within the last8 days across all years
List<DefCveItem> recentlyChangedEntries = new ArrayList<>();

for (int currentYear = START_YEAR; currentYear <= Year.now().getValue(); currentYear++) {
for (int currentYear = EARLIEST_CVE_YEAR; currentYear <= Year.now().getValue(); currentYear++) {

// Be forgiving, if we fail to fetch a year, we just continue with the next one
try {
// reset our filters for each year
apiBuilder.removeLastModifiedFilter();
apiBuilder.removePublishDateFilter();

Path cacheFilePath = buildCacheTargetFile(properties, String.valueOf(currentYear));
Path cacheFilePath = buildCacheTargetFile(properties, currentYear);
LOG.info("INFO *** Processing year {} ***", currentYear);
CvesNvdPojo existingCacheData = loadExistingCacheAndConfigureApi(apiBuilder, currentYear,
cacheFilePath);
Expand All @@ -310,7 +310,7 @@ private Integer processRequest(NvdCveClientBuilder apiBuilder, CacheProperties p
if (cvesForYear.lastUpdated != null) {
properties.set("lastModifiedDate", cvesForYear.lastUpdated);
}
storeToCache(String.valueOf(currentYear), cvesForYear, properties);
storeToCache(currentYear, cvesForYear, properties);
LOG.info("INFO *** Finished year {} with #{} entries ***", currentYear,
cvesForYear.vulnerabilities.size());

Expand Down Expand Up @@ -399,6 +399,14 @@ private CvesNvdPojo aggregateCvesForYear(int year, NvdCveClientBuilder apiBuilde
return finalResult;
}

private void storeToCache(int year, CvesNvdPojo cves, CacheProperties properties) {
int target = year;
if (target < START_YEAR) {
target = START_YEAR;
}
storeToCache(String.valueOf(target), cves, properties);
}

/**
* Given the CVEs for the year, stores all of them in a json cache file and a meta-dat file. creates
* nvdcve-$year.json.gz and nvdcve-$year.meta
Expand Down Expand Up @@ -516,6 +524,14 @@ private ZonedDateTime determineExistingCacheFileLastChanged(Path cacheFilePath)
ZoneOffset.UTC);
}

private Path buildCacheTargetFile(CacheProperties properties, int year) {
int target = year;
if (target < START_YEAR) {
target = START_YEAR;
}
return buildCacheTargetFile(properties, String.valueOf(target));
}

private Path buildCacheTargetFile(CacheProperties properties, String target) {
final String prefix = properties.get("prefix", "nvdcve-");
return Path.of(properties.getDirectory().getPath(), prefix + target + ".json.gz");
Expand Down

0 comments on commit 4eced1d

Please sign in to comment.