diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java index 65bed45b48..f2dcca36aa 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/utils/FileUtils.java @@ -235,8 +235,8 @@ public class FileUtils { } public static void moveFileToDir(String filePath, String targetPath) { - copyFileToDir(filePath, targetPath); - deleteFile(filePath); + copyFileToDir(filePath, targetPath); + deleteFile(filePath); } private static void copyFileToDir(File file, File targetDir) { @@ -348,9 +348,12 @@ public class FileUtils { } public static void deleteFile(String path) { - File file = new File(path); - if (file.exists()) { - file.delete(); + if (StringUtils.isNotBlank(path)) { + validateFileName(path); + File file = new File(path); + if (file.exists()) { + file.delete(); + } } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/CommandService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/CommandService.java index 8dfba4a2ab..36c1e2fb6d 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/CommandService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/environment/service/CommandService.java @@ -161,9 +161,9 @@ public class CommandService { } } - public boolean checkKeyStore(String password, String path) { + public void checkKeyStore(String password, String path) { try { - String keytoolArgs[] = {"keytool", "-rfc", "-list", "-keystore", path, "-storepass", password}; + String[] keytoolArgs = {"keytool", "-rfc", "-list", "-keystore", path, "-storepass", password}; Process p = new ProcessBuilder(keytoolArgs).start(); try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()))) { String line = null; @@ -176,11 +176,9 @@ public class CommandService { } } } - return true; } catch (Exception e) { LogUtil.error(e); MSException.throwException(e.getMessage()); - return false; } } } diff --git a/test-track/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java b/test-track/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java index 225c62fd69..53116a2d66 100644 --- a/test-track/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java +++ b/test-track/backend/src/main/java/io/metersphere/xmind/utils/FileUtil.java @@ -36,7 +36,8 @@ public class FileUtil { */ public static File multipartFileToFile(MultipartFile file) { if (file != null && file.getSize() > 0) { - try (InputStream ins = file.getInputStream();) { + try (InputStream ins = file.getInputStream()) { + FileUtils.validateFileName(file.getOriginalFilename()); File toFile = new File(file.getOriginalFilename()); inputStreamToFile(ins, toFile); return toFile; @@ -49,17 +50,18 @@ public class FileUtil { /** * File 转 MultipartFile + * * @param file * @return */ public static MultipartFile fileToMultipartFile(File file) { DiskFileItem item = new DiskFileItem("file", MediaType.MULTIPART_FORM_DATA_VALUE, true, - file.getName(), (int)file.length(), file.getParentFile()); + file.getName(), (int) file.length(), file.getParentFile()); try { OutputStream os = item.getOutputStream(); os.write(FileUtils.fileToByte(file)); } catch (IOException e) { - e.printStackTrace(); + LogUtil.error(e); } return new CommonsMultipartFile(item); }