Skip to content

Commit

Permalink
Merge pull request from GHSA-269q-hmxg-m83q
Browse files Browse the repository at this point in the history
* Correctly modify permission for temporary files when using Java 6 in all cases

Motivation:

[GHSA-5mcr-gq6c-3hq2](GHSA-5mcr-gq6c-3hq2) did not correctly fix all cases for temprory files when running on java 6.

Modifications:

- Add correctly adjust perms in all cases
- Add logging if adjusting of permissions fails

Result:

Fixes GHSA-269q-hmxg-m83q

* Throw on failure
  • Loading branch information
normanmaurer committed May 6, 2022
1 parent 7dbca6a commit 185f8b2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions common/src/main/java/io/netty/util/internal/PlatformDependent.java
Expand Up @@ -1447,13 +1447,20 @@ public static File createTempFile(String prefix, String suffix, File directory)
}
return Files.createTempFile(directory.toPath(), prefix, suffix).toFile();
}
final File file;
if (directory == null) {
return File.createTempFile(prefix, suffix);
file = File.createTempFile(prefix, suffix);
} else {
file = File.createTempFile(prefix, suffix, directory);
}
File file = File.createTempFile(prefix, suffix, directory);

// Try to adjust the perms, if this fails there is not much else we can do...
file.setReadable(false, false);
file.setReadable(true, true);
if (!file.setReadable(false, false)) {
throw new IOException("Failed to set permissions on temporary file " + file);
}
if (!file.setReadable(true, true)) {
throw new IOException("Failed to set permissions on temporary file " + file);
}
return file;
}

Expand Down

0 comments on commit 185f8b2

Please sign in to comment.