Bläddra i källkod

修复安全性漏洞的问题.

https://github.com/baomidou/mybatis-plus/issues/5795
nieqiurong 1 år sedan
förälder
incheckning
56aacb410d

+ 8 - 2
mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/util/RuntimeUtils.java

@@ -18,6 +18,7 @@ package com.baomidou.mybatisplus.generator.util;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.File;
 import java.io.IOException;
 import java.text.MessageFormat;
 
@@ -38,6 +39,11 @@ public class RuntimeUtils {
      * @throws IOException
      */
     public static void openDir(String outDir) throws IOException {
+        File file = new File(outDir);
+        if (!file.isDirectory()) {
+            LOGGER.error("illegal directory:{}", outDir);
+            throw new IllegalArgumentException("Illegal directory " + outDir);
+        }
         String osName = System.getProperty("os.name");
         if (osName != null) {
             if (osName.contains("Mac")) {
@@ -45,10 +51,10 @@ public class RuntimeUtils {
             } else if (osName.contains("Windows")) {
                 Runtime.getRuntime().exec(MessageFormat.format("cmd /c start \"\" \"{0}\"", outDir));
             } else {
-                LOGGER.debug("文件输出目录:{}", outDir);
+                LOGGER.debug("file output directory:{}", outDir);
             }
         } else {
-            LOGGER.warn("读取操作系统失败");
+            LOGGER.warn("read operating system failed!");
         }
     }
 }