mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
修复FileUtil.createTempFile可能导致的漏洞
This commit is contained in:
parent
6896fed4c1
commit
c33550f703
@ -22,6 +22,7 @@
|
||||
* 【http 】 修复HttpDownloader.downloadFile 方法缺少static问题(issue#I6Z8VU@Gitee)
|
||||
* 【core 】 修复NumberUtil mul 传入null的string入参报错问题(issue#I70JB3@Gitee)
|
||||
* 【core 】 修复ZipReader.get调用reset异常问题(issue#3099@Github)
|
||||
* 【core 】 修复FileUtil.createTempFile可能导致的漏洞(issue#3103@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.18 (2023-04-27)
|
||||
|
@ -1004,7 +1004,9 @@ public class FileUtil extends PathUtil {
|
||||
int exceptionsCount = 0;
|
||||
while (true) {
|
||||
try {
|
||||
File file = File.createTempFile(prefix, suffix, mkdir(dir)).getCanonicalFile();
|
||||
// https://github.com/dromara/hutool/issues/3103
|
||||
//File file = File.createTempFile(prefix, suffix, mkdir(dir)).getCanonicalFile();
|
||||
final File file = PathUtil.createTempFile(prefix, suffix, null == dir ? null : dir.toPath()).toFile().getCanonicalFile();
|
||||
if (isReCreat) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
file.delete();
|
||||
|
@ -668,6 +668,34 @@ public class PathUtil {
|
||||
return path.getFileName().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时文件<br>
|
||||
* 创建后的文件名为 prefix[Random].suffix From com.jodd.io.FileUtil
|
||||
*
|
||||
* @param prefix 前缀,至少3个字符
|
||||
* @param suffix 后缀,如果null则使用默认.tmp
|
||||
* @param dir 临时文件创建的所在目录
|
||||
* @return 临时文件
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public static Path createTempFile(final String prefix, final String suffix, final Path dir) throws IORuntimeException {
|
||||
int exceptionsCount = 0;
|
||||
while (true) {
|
||||
try {
|
||||
if(null == dir){
|
||||
return Files.createTempFile(prefix, suffix);
|
||||
}else{
|
||||
return Files.createTempFile(mkdir(dir), prefix, suffix);
|
||||
}
|
||||
} catch (final IOException ioex) { // fixes java.io.WinNTFileSystem.createFileExclusively access denied
|
||||
if (++exceptionsCount >= 50) {
|
||||
throw new IORuntimeException(ioex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件或空目录,不追踪软链
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user