Skip to content

Race Condition vulnerability #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
import java.nio.file.Files;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -178,15 +179,12 @@ public static File createTempDirectory() throws IOException {
}

public static File createTempDirectory(File location) throws IOException {
final File temp = File.createTempFile("tmp", Long.toString(System.nanoTime()), location);
if (!(temp.delete())) {
throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
// Use Files.createTempDirectory to avoid race condition
if (location != null) {
return Files.createTempDirectory(location.toPath(), "tmp" + Long.toString(System.nanoTime())).toFile();
} else {
return Files.createTempDirectory("tmp" + Long.toString(System.nanoTime())).toFile();
}
//Known race condition exists here, not sure what an attacker would accomplish with it though
if (!temp.mkdir()) {
throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
}
return temp;
}

/**
Expand Down