mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-23 09:31:32 +01:00
added a mechanism to copy the global settings object to forked threads
Former-commit-id: 2932ae216d79d3cd08f4fb57695f3bd979c95c59
This commit is contained in:
@@ -118,7 +118,7 @@ public class StandardUpdate {
|
|||||||
final Set<Future<Future<ProcessTask>>> downloadFutures = new HashSet<Future<Future<ProcessTask>>>(maxUpdates);
|
final Set<Future<Future<ProcessTask>>> downloadFutures = new HashSet<Future<Future<ProcessTask>>>(maxUpdates);
|
||||||
for (NvdCveInfo cve : updateable) {
|
for (NvdCveInfo cve : updateable) {
|
||||||
if (cve.getNeedsUpdate()) {
|
if (cve.getNeedsUpdate()) {
|
||||||
final CallableDownloadTask call = new CallableDownloadTask(cve, processExecutor, cveDB);
|
final CallableDownloadTask call = new CallableDownloadTask(cve, processExecutor, cveDB, Settings.getInstance());
|
||||||
downloadFutures.add(downloadExecutors.submit(call));
|
downloadFutures.add(downloadExecutors.submit(call));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,10 +45,11 @@ public class CallableDownloadTask implements Callable<Future<ProcessTask>> {
|
|||||||
* @param processor the processor service to submit the downloaded files to
|
* @param processor the processor service to submit the downloaded files to
|
||||||
* @param cveDB the CVE DB to use to store the vulnerability data
|
* @param cveDB the CVE DB to use to store the vulnerability data
|
||||||
*/
|
*/
|
||||||
public CallableDownloadTask(NvdCveInfo nvdCveInfo, ExecutorService processor, CveDB cveDB) {
|
public CallableDownloadTask(NvdCveInfo nvdCveInfo, ExecutorService processor, CveDB cveDB, Settings settings) {
|
||||||
this.nvdCveInfo = nvdCveInfo;
|
this.nvdCveInfo = nvdCveInfo;
|
||||||
this.processorService = processor;
|
this.processorService = processor;
|
||||||
this.cveDB = cveDB;
|
this.cveDB = cveDB;
|
||||||
|
this.settings = settings;
|
||||||
|
|
||||||
final File file1;
|
final File file1;
|
||||||
final File file2;
|
final File file2;
|
||||||
@@ -75,6 +76,10 @@ public class CallableDownloadTask implements Callable<Future<ProcessTask>> {
|
|||||||
* The NVD CVE Meta Data.
|
* The NVD CVE Meta Data.
|
||||||
*/
|
*/
|
||||||
private NvdCveInfo nvdCveInfo;
|
private NvdCveInfo nvdCveInfo;
|
||||||
|
/**
|
||||||
|
* A reference to the global settings object.
|
||||||
|
*/
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value of nvdCveInfo.
|
* Get the value of nvdCveInfo.
|
||||||
@@ -163,6 +168,7 @@ public class CallableDownloadTask implements Callable<Future<ProcessTask>> {
|
|||||||
@Override
|
@Override
|
||||||
public Future<ProcessTask> call() throws Exception {
|
public Future<ProcessTask> call() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
Settings.setInstance(settings);
|
||||||
final URL url1 = new URL(nvdCveInfo.getUrl());
|
final URL url1 = new URL(nvdCveInfo.getUrl());
|
||||||
final URL url2 = new URL(nvdCveInfo.getOldSchemaVersionUrl());
|
final URL url2 = new URL(nvdCveInfo.getOldSchemaVersionUrl());
|
||||||
String msg = String.format("Download Started for NVD CVE - %s", nvdCveInfo.getId());
|
String msg = String.format("Download Started for NVD CVE - %s", nvdCveInfo.getId());
|
||||||
@@ -180,13 +186,15 @@ public class CallableDownloadTask implements Callable<Future<ProcessTask>> {
|
|||||||
msg = String.format("Download Complete for NVD CVE - %s", nvdCveInfo.getId());
|
msg = String.format("Download Complete for NVD CVE - %s", nvdCveInfo.getId());
|
||||||
Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.INFO, msg);
|
Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.INFO, msg);
|
||||||
|
|
||||||
final ProcessTask task = new ProcessTask(cveDB, this);
|
final ProcessTask task = new ProcessTask(cveDB, this, settings);
|
||||||
return this.processorService.submit(task);
|
return this.processorService.submit(task);
|
||||||
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
final String msg = String.format("An exception occurred downloading NVD CVE - %s%nSome CVEs may not be reported.", nvdCveInfo.getId());
|
final String msg = String.format("An exception occurred downloading NVD CVE - %s%nSome CVEs may not be reported.", nvdCveInfo.getId());
|
||||||
Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.WARNING, msg);
|
Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.WARNING, msg);
|
||||||
Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.FINE, "Download Task Failed", ex);
|
Logger.getLogger(CallableDownloadTask.class.getName()).log(Level.FINE, "Download Task Failed", ex);
|
||||||
|
} finally {
|
||||||
|
Settings.cleanup();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.owasp.dependencycheck.data.update.exception.UpdateException;
|
|||||||
import org.owasp.dependencycheck.data.update.xml.NvdCve12Handler;
|
import org.owasp.dependencycheck.data.update.xml.NvdCve12Handler;
|
||||||
import org.owasp.dependencycheck.data.update.xml.NvdCve20Handler;
|
import org.owasp.dependencycheck.data.update.xml.NvdCve20Handler;
|
||||||
import org.owasp.dependencycheck.dependency.VulnerableSoftware;
|
import org.owasp.dependencycheck.dependency.VulnerableSoftware;
|
||||||
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +81,10 @@ public class ProcessTask implements Callable<ProcessTask> {
|
|||||||
* A reference to the properties.
|
* A reference to the properties.
|
||||||
*/
|
*/
|
||||||
private final DatabaseProperties properties;
|
private final DatabaseProperties properties;
|
||||||
|
/**
|
||||||
|
* A reference to the global settings object.
|
||||||
|
*/
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new ProcessTask used to process an NVD CVE update.
|
* Constructs a new ProcessTask used to process an NVD CVE update.
|
||||||
@@ -87,10 +92,11 @@ public class ProcessTask implements Callable<ProcessTask> {
|
|||||||
* @param cveDB the data store object
|
* @param cveDB the data store object
|
||||||
* @param filePair the download task that contains the URL references to download
|
* @param filePair the download task that contains the URL references to download
|
||||||
*/
|
*/
|
||||||
public ProcessTask(final CveDB cveDB, final CallableDownloadTask filePair) {
|
public ProcessTask(final CveDB cveDB, final CallableDownloadTask filePair, Settings settings) {
|
||||||
this.cveDB = cveDB;
|
this.cveDB = cveDB;
|
||||||
this.filePair = filePair;
|
this.filePair = filePair;
|
||||||
this.properties = cveDB.getDatabaseProperties();
|
this.properties = cveDB.getDatabaseProperties();
|
||||||
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,9 +109,12 @@ public class ProcessTask implements Callable<ProcessTask> {
|
|||||||
@Override
|
@Override
|
||||||
public ProcessTask call() throws Exception {
|
public ProcessTask call() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
Settings.setInstance(settings);
|
||||||
processFiles();
|
processFiles();
|
||||||
} catch (UpdateException ex) {
|
} catch (UpdateException ex) {
|
||||||
this.exception = ex;
|
this.exception = ex;
|
||||||
|
} finally {
|
||||||
|
Settings.cleanup();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,6 +258,24 @@ public final class Settings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the underlying instance of the Settings object.
|
||||||
|
*
|
||||||
|
* @return the Settings object
|
||||||
|
*/
|
||||||
|
public static Settings getInstance() {
|
||||||
|
return THREAD_LOCAL.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the instance of the Settings object to use in this thread.
|
||||||
|
*
|
||||||
|
* @param instance the instance of the settings object to use in this thread
|
||||||
|
*/
|
||||||
|
public static void setInstance(Settings instance) {
|
||||||
|
THREAD_LOCAL.set(instance);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the properties. This will not log any properties that contain 'password' in the key.
|
* Logs the properties. This will not log any properties that contain 'password' in the key.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user