瀏覽代碼

cmSystemTools: Fix ParseArguments out-of-bounds read

When checking for a Windows-style leading path, do not read past the
null terminator.

Issue: #17854
Brad King 7 年之前
父節點
當前提交
75e8af3354
共有 1 個文件被更改,包括 7 次插入6 次删除
  1. 7 6
      Source/cmSystemTools.cxx

+ 7 - 6
Source/cmSystemTools.cxx

@@ -550,12 +550,13 @@ std::vector<std::string> cmSystemTools::ParseArguments(const char* command)
 
 
   bool win_path = false;
   bool win_path = false;
 
 
-  if ((command[0] != '/' && command[1] == ':' && command[2] == '\\') ||
-      (command[0] == '\"' && command[1] != '/' && command[2] == ':' &&
-       command[3] == '\\') ||
-      (command[0] == '\'' && command[1] != '/' && command[2] == ':' &&
-       command[3] == '\\') ||
-      (command[0] == '\\' && command[1] == '\\')) {
+  if (command[0] && command[1] &&
+      ((command[0] != '/' && command[1] == ':' && command[2] == '\\') ||
+       (command[0] == '\"' && command[1] != '/' && command[2] == ':' &&
+        command[3] == '\\') ||
+       (command[0] == '\'' && command[1] != '/' && command[2] == ':' &&
+        command[3] == '\\') ||
+       (command[0] == '\\' && command[1] == '\\'))) {
     win_path = true;
     win_path = true;
   }
   }
   // Split the command into an argv array.
   // Split the command into an argv array.