diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractSuppressionAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractSuppressionAnalyzer.java index d8ea190cd..e614bf7c6 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractSuppressionAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractSuppressionAnalyzer.java @@ -112,10 +112,7 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer { final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE); if (uriRx.matcher(suppressionFilePath).matches()) { deleteTempFile = true; - file = File.createTempFile("suppression", ".xml", Settings.getTempDirectory()); - if (file.exists()) { - file.delete(); - } + file = FileUtils.getTempFile("suppression", "xml"); final URL url = new URL(suppressionFilePath); try { Downloader.fetchFile(url, file, false); diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java index bcbb59dd6..fc3c4a31b 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java @@ -26,6 +26,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; @@ -86,6 +87,26 @@ public final class FileUtils { return success; } + /** + * Generates a new temporary file name that is guaranteed to be unique. + * + * @param prefix the prefix for the file name to generate + * @param extension the extension of the generated file name + * @return a temporary File + */ + public static File getTempFile(String prefix, String extension) { + final File dir = Settings.getTempDirectory(); + if (!dir.exists()) { + dir.mkdirs(); + } + final String tempFileName = String.format("%s%s.%s", prefix, UUID.randomUUID().toString(), extension); + final File tempFile = new File(dir, tempFileName); + if (tempFile.exists()) { + return getTempFile(prefix, extension); + } + return tempFile; + } + /** * Returns the data directory. If a path was specified in dependencycheck.properties or was specified using the * Settings object, and the path exists, that path will be returned as a File object. If it does not exist, then a