瀏覽代碼

Fix mg_path_suspicious for Windows

bel2125 4 年之前
父節點
當前提交
a07a183c56
共有 1 個文件被更改,包括 17 次插入10 次删除
  1. 17 10
      src/civetweb.c

+ 17 - 10
src/civetweb.c

@@ -3447,7 +3447,7 @@ static int mg_stat(const struct mg_connection *conn,
                    struct mg_file_stat *filep);
 
 
-/* Reject files with special characters */
+/* Reject files with special characters (for Windows) */
 static int
 mg_path_suspicious(const struct mg_connection *conn, const char *path)
 {
@@ -3459,28 +3459,35 @@ mg_path_suspicious(const struct mg_connection *conn, const char *path)
 		return 1;
 	}
 
+#if defined(_WIN32)
 	while (*c) {
 		if (*c <= 32) {
 			/* Control character or space */
-			return 0;
+			return 1;
 		}
 		if ((*c == '>') || (*c == '<') || (*c == '|')) {
 			/* stdin/stdout redirection character */
-			return 0;
+			return 1;
 		}
-#if defined(_WIN32)
 		if (*c == '\\') {
 			/* Windows backslash */
-			return 0;
+			return 1;
 		}
-#else
-		if (*c == '&') {
-			/* Linux ampersand */
-			return 0;
+		if (*c == ':') {
+			/* Windows drive letter */
+			return 1;
+		}
+		if ((*c == '*') || (*c == '?')) {
+			/* Wildcard character */
+			return 1;
+		}
+		if (*c == '"') {
+			/* Windows drive letter */
+			return 1;
 		}
-#endif
 		c++;
 	}
+#endif
 
 	/* Nothing suspicious found */
 	return 0;