mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-20 00:04:27 +01:00
updated to resolve issue #58
Former-commit-id: 4cd1d528f33c8db05a7d0b67460311b1b56426cd
This commit is contained in:
@@ -18,13 +18,20 @@
|
|||||||
package org.owasp.dependencycheck.analyzer;
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionParseException;
|
import org.owasp.dependencycheck.suppression.SuppressionParseException;
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionParser;
|
import org.owasp.dependencycheck.suppression.SuppressionParser;
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
||||||
|
import org.owasp.dependencycheck.utils.DownloadFailedException;
|
||||||
|
import org.owasp.dependencycheck.utils.Downloader;
|
||||||
|
import org.owasp.dependencycheck.utils.FileUtils;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +102,24 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
* @throws SuppressionParseException thrown if the XML cannot be parsed.
|
* @throws SuppressionParseException thrown if the XML cannot be parsed.
|
||||||
*/
|
*/
|
||||||
private void loadSuppressionData() throws SuppressionParseException {
|
private void loadSuppressionData() throws SuppressionParseException {
|
||||||
final File file = Settings.getFile(Settings.KEYS.SUPPRESSION_FILE);
|
String suppressionFilePath = Settings.getString(Settings.KEYS.SUPPRESSION_FILE);
|
||||||
|
if (suppressionFilePath == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File file = null;
|
||||||
|
boolean deleteTempFile = false;
|
||||||
|
try {
|
||||||
|
Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
||||||
|
if (uriRx.matcher(suppressionFilePath).matches()) {
|
||||||
|
file = File.createTempFile("suppression", "xml", Settings.getTempDirectory());
|
||||||
|
URL url = new URL(suppressionFilePath);
|
||||||
|
try {
|
||||||
|
Downloader.fetchFile(url, file, false);
|
||||||
|
} catch (DownloadFailedException ex) {
|
||||||
|
Downloader.fetchFile(url, file, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
final SuppressionParser parser = new SuppressionParser();
|
final SuppressionParser parser = new SuppressionParser();
|
||||||
try {
|
try {
|
||||||
@@ -108,5 +132,25 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (DownloadFailedException ex) {
|
||||||
|
Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING,
|
||||||
|
"Unable to fetch the configured suppression file");
|
||||||
|
Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.FINE, "", ex);
|
||||||
|
throw new SuppressionParseException("Unable to fetch the configured suppression file", ex);
|
||||||
|
} catch (MalformedURLException ex) {
|
||||||
|
Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING,
|
||||||
|
"Configured suppression file has an invalid URL");
|
||||||
|
Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.FINE, "", ex);
|
||||||
|
throw new SuppressionParseException("Configured suppression file has an invalid URL", ex);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING,
|
||||||
|
"Unable to create temp file for suppressions");
|
||||||
|
Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.FINE, "", ex);
|
||||||
|
throw new SuppressionParseException("Unable to create temp file for suppressions", ex);
|
||||||
|
} finally {
|
||||||
|
if (deleteTempFile && file != null) {
|
||||||
|
FileUtils.delete(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user