diff --git a/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java b/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java index a10b3c9..6be063a 100644 --- a/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java +++ b/vulnz/src/main/java/io/github/jeremylong/vulnz/cli/commands/CveCommand.java @@ -282,7 +282,7 @@ private Integer processRequest(NvdCveClientBuilder apiBuilder, CacheProperties p // will hold all entries that have been changed within the last8 days across all years List 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 { @@ -290,7 +290,7 @@ private Integer processRequest(NvdCveClientBuilder apiBuilder, CacheProperties p 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); @@ -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()); @@ -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 @@ -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");