Skip to content

Commit 3bf6e1e

Browse files
author
Vincent Potucek
committed
Apply security fixes featuring refasterrules.FileRulesRecipes
1 parent 79f9ebd commit 3bf6e1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+109
-110
lines changed

core/src/main/java/hudson/FilePath.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ public Void invoke(File dir, VirtualChannel channel) throws IOException {
680680
}
681681

682682
private static void unzip(File dir, InputStream in) throws IOException {
683-
File tmpFile = File.createTempFile("tmpzip", null); // uses java.io.tmpdir
683+
File tmpFile = Files.createTempFile("tmpzip", null).toFile(); // uses java.io.tmpdir
684684
try {
685685
// TODO why does this not simply use ZipInputStream?
686686
IOUtils.copy(in, tmpFile);
@@ -1582,7 +1582,7 @@ private static class CreateTempFile extends MasterToSlaveFileCallable<String> {
15821582

15831583
@Override
15841584
public String invoke(File dir, VirtualChannel channel) throws IOException {
1585-
File f = File.createTempFile(prefix, suffix, dir);
1585+
File f = Files.createTempFile(dir.toPath(), prefix, suffix).toFile();
15861586
return f.getName();
15871587
}
15881588
}
@@ -1660,7 +1660,7 @@ public String invoke(File dir, VirtualChannel channel) throws IOException {
16601660

16611661
File f;
16621662
try {
1663-
f = File.createTempFile(prefix, suffix, dir);
1663+
f = Files.createTempFile(dir.toPath(), prefix, suffix).toFile();
16641664
} catch (IOException e) {
16651665
throw new IOException("Failed to create a temporary directory in " + dir, e);
16661666
}

core/src/main/java/hudson/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static int remotePost(String[] args) throws Exception {
143143
}
144144

145145
// write the output to a temporary file first.
146-
File tmpFile = File.createTempFile("jenkins", "log");
146+
File tmpFile = Files.createTempFile("jenkins", "log").toFile();
147147
try {
148148
int ret;
149149
try (OutputStream os = Files.newOutputStream(tmpFile.toPath());

core/src/main/java/hudson/PluginManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import java.net.http.HttpRequest;
8989
import java.nio.file.Files;
9090
import java.nio.file.InvalidPathException;
91-
import java.nio.file.Paths;
91+
import java.nio.file.Path;
9292
import java.nio.file.attribute.FileTime;
9393
import java.security.CodeSource;
9494
import java.time.Duration;
@@ -1396,7 +1396,7 @@ public PluginWrapper whichPlugin(Class c) {
13961396
if ("file".equals(loc.getProtocol())) {
13971397
File file;
13981398
try {
1399-
file = Paths.get(loc.toURI()).toFile();
1399+
file = Path.of(loc.toURI()).toFile();
14001400
} catch (InvalidPathException | URISyntaxException e) {
14011401
LOGGER.log(Level.WARNING, "could not inspect " + loc, e);
14021402
return null;
@@ -1962,7 +1962,7 @@ private HttpResponse doUploadPluginImpl(StaplerRequest2 req) throws IOException,
19621962
}
19631963

19641964
// first copy into a temporary file name
1965-
File t = File.createTempFile("uploaded", ".jpi", tmpDir);
1965+
File t = Files.createTempFile(tmpDir.toPath(), "uploaded", ".jpi").toFile();
19661966
tmpDir.deleteOnExit();
19671967
t.deleteOnExit();
19681968
// TODO Remove this workaround after FILEUPLOAD-293 is resolved.

core/src/main/java/hudson/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ private static void reportAtomicFailure(@NonNull Path pathForSymlink, @NonNull E
13061306
@CheckReturnValue
13071307
private static boolean createSymlinkAtomic(@NonNull Path pathForSymlink, @NonNull File fileForSymlink, @NonNull Path target, @NonNull String symlinkPath) {
13081308
try {
1309-
File symlink = File.createTempFile("symtmp", null, fileForSymlink);
1309+
File symlink = Files.createTempFile(fileForSymlink.toPath(), "symtmp", null).toFile();
13101310
tryToDeleteSymlink(symlink);
13111311
Path tempSymlinkPath = symlink.toPath();
13121312
Files.createSymbolicLink(tempSymlinkPath, target);

core/src/main/java/hudson/WebAppMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public Locale get() {
224224
// even if the temp directory doesn't exist.
225225
// check that and report an error
226226
try {
227-
File f = File.createTempFile("test", "test");
227+
File f = Files.createTempFile("test", "test").toFile();
228228
boolean result = f.delete();
229229
if (!result) {
230230
LOGGER.log(FINE, "Temp file test.test could not be deleted.");

core/src/main/java/hudson/cli/InstallPluginCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ protected int run() throws Exception {
169169
}
170170

171171
private static File getTmpFile() throws Exception {
172-
return File.createTempFile("download", ".jpi.tmp", Jenkins.get().getPluginManager().rootDir);
172+
return Files.createTempFile(Jenkins.get().getPluginManager().rootDir.toPath(), "download", ".jpi.tmp").toFile();
173173
}
174174

175175
private static File moveToFinalLocation(File tmpFile) throws Exception {

core/src/main/java/hudson/scm/SCM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ public void checkout(
516516
BuildListener.class,
517517
File.class)) {
518518
if (changelogFile == null) {
519-
changelogFile = File.createTempFile("changelog", ".xml");
519+
changelogFile = Files.createTempFile("changelog", ".xml").toFile();
520520
try {
521521
if (!checkout((AbstractBuild) build, launcher, workspace, (BuildListener) listener, changelogFile)) {
522522
throw new AbortException();

core/src/main/java/hudson/util/AtomicFileWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public AtomicFileWriter(@NonNull Path destinationPath, @NonNull Charset charset,
155155

156156
try {
157157
// JENKINS-48407: NIO's createTempFile creates file with 0600 permissions, so we use pre-NIO for this...
158-
tmpPath = File.createTempFile(destPath.getFileName() + "-atomic", "tmp", dir.toFile()).toPath();
158+
tmpPath = Files.createTempFile(dir, destPath.getFileName() + "-atomic", "tmp");
159159
} catch (IOException e) {
160160
throw new IOException("Failed to create a temporary file in " + dir, e);
161161
}

core/src/main/java/hudson/util/RemotingDiagnostics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static FilePath getHeapDump(VirtualChannel channel) throws IOException, I
184184
private static class GetHeapDump extends MasterToSlaveCallable<FilePath, IOException> {
185185
@Override
186186
public FilePath call() throws IOException {
187-
final File hprof = File.createTempFile("hudson-heapdump", ".hprof");
187+
final File hprof = Files.createTempFile("hudson-heapdump", ".hprof").toFile();
188188
Files.delete(Util.fileToPath(hprof));
189189
try {
190190
MBeanServer server = ManagementFactory.getPlatformMBeanServer();

core/src/main/java/jenkins/install/SetupWizard.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private void createInitialApiToken(User user) throws IOException, InterruptedExc
245245
}
246246

247247
try {
248-
plainText = Files.readString(apiTokenFile, StandardCharsets.UTF_8);
248+
plainText = Files.readString(apiTokenFile);
249249
LOGGER.log(Level.INFO, "API Token generated using contents of file: {0}", apiTokenFile.toAbsolutePath());
250250
} catch (IOException e) {
251251
LOGGER.log(Level.WARNING, String.format("The API Token cannot be retrieved from the file: %s", apiTokenFile), e);
@@ -483,7 +483,7 @@ public VersionNumber getCurrentLevel() {
483483
File state = getUpdateStateFile();
484484
if (state.exists()) {
485485
try {
486-
String version = Files.readString(Util.fileToPath(state), StandardCharsets.UTF_8);
486+
String version = Files.readString(Util.fileToPath(state));
487487
if (version == null || version.isBlank()) {
488488
version = "1.0";
489489
}

0 commit comments

Comments
 (0)