Skip to content

Commit

Permalink
Added guard against empty messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ctevse committed Nov 21, 2023
1 parent 0157524 commit 5be0c25
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
46 changes: 24 additions & 22 deletions productnameextractor/src/main/java/messenger/Messenger.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,31 @@ public void run() {
String message = new String(delivery.getBody(), StandardCharsets.UTF_8);
List<String> cveIds = parseIds(message);

logger.info("Received job with CVE(s) {}", cveIds);

// Pull specific cve information from database for each CVE ID passed from reconciler
List<CompositeVulnerability> vulnList = databaseHelper.getSpecificCompositeVulnerabilities(cveIds);

// Identify affected products from the CVEs
final long getProdStart = System.currentTimeMillis();
List<AffectedProduct> affectedProducts = affectedProductIdentifier.identifyAffectedProducts(vulnList);

// Insert the affected products found into the database
databaseHelper.insertAffectedProductsToDB(affectedProducts);
logger.info("Product Name Extractor found and inserted {} affected products to the database in {} seconds", affectedProducts.size(), Math.floor(((double) (System.currentTimeMillis() - getProdStart) / 1000) * 100) / 100);

// Clear cveIds, extract only the cveIds for which affected products were found to be sent to the Patchfinder
cveIds.clear();
for (AffectedProduct affectedProduct : affectedProducts) {
if (!cveIds.contains(affectedProduct.getCveId())) cveIds.add(affectedProduct.getCveId());
if(!cveIds.isEmpty()){
logger.info("Received job with CVE(s) {}", cveIds);

// Pull specific cve information from database for each CVE ID passed from reconciler
List<CompositeVulnerability> vulnList = databaseHelper.getSpecificCompositeVulnerabilities(cveIds);

// Identify affected products from the CVEs
final long getProdStart = System.currentTimeMillis();
List<AffectedProduct> affectedProducts = affectedProductIdentifier.identifyAffectedProducts(vulnList);

// Insert the affected products found into the database
databaseHelper.insertAffectedProductsToDB(affectedProducts);
logger.info("Product Name Extractor found and inserted {} affected products to the database in {} seconds", affectedProducts.size(), Math.floor(((double) (System.currentTimeMillis() - getProdStart) / 1000) * 100) / 100);

// Clear cveIds, extract only the cveIds for which affected products were found to be sent to the Patchfinder
cveIds.clear();
for (AffectedProduct affectedProduct : affectedProducts) {
if (!cveIds.contains(affectedProduct.getCveId())) cveIds.add(affectedProduct.getCveId());
}

logger.info("Sending jobs to patchfinder...");
String response = genJson(cveIds);
channel.basicPublish("", outputQueue, null, response.getBytes(StandardCharsets.UTF_8));
logger.info("Jobs have been sent!\n\n");
}

logger.info("Sending jobs to patchfinder...");
String response = genJson(cveIds);
channel.basicPublish("", outputQueue, null, response.getBytes(StandardCharsets.UTF_8));
logger.info("Jobs have been sent!\n\n");
};

channel.basicConsume(inputQueue, true, deliverCallback, consumerTag -> {});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"compTime":"2023-06-13T19:58:32.350096800Z","refreshTime":"2023-11-21T21:49:50.367428501Z","products":{"Key1":{"vendor":"Vendor1","product":"Product1","groupID":"Vendor1:Product1","commonTitle":"CommonTitle1","versions":{"1.0":{"title":"Title1","version":"1.0","update":"Update1","cpeID":"CpeID1","platform":"Platform1"}}},"Key2":{"vendor":"Vendor2","product":"Product2","groupID":"Vendor2:Product2","commonTitle":"CommonTitle2","versions":{"2.0":{"title":"Title2","version":"2.0","update":"Update2","cpeID":"CpeID2","platform":"Platform2"},"2.1":{"title":"Title2","version":"2.1","update":"Update2","cpeID":"CpeID2","platform":"Platform2"}}},"Key3":{"vendor":"Vendor3","product":"Product3","groupID":"Vendor3:Product3","commonTitle":"CommonTitle3","versions":{"3.0":{"title":"Title3","version":"3.0","update":"Update3","cpeID":"CpeID3","platform":"Platform3"}}}}}
Empty file.

0 comments on commit 5be0c25

Please sign in to comment.