浏览代码

mg_send_file fails unchecked if called with a directory name

bel 10 年之前
父节点
当前提交
e162202932
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      src/civetweb.c

+ 10 - 1
src/civetweb.c

@@ -3964,7 +3964,16 @@ void mg_send_file(struct mg_connection *conn, const char *path)
 {
     struct file file = STRUCT_FILE_INITIALIZER;
     if (mg_stat(conn, path, &file)) {
-        handle_static_file_request(conn, path, &file);
+        if (file.is_directory) {
+            if (!mg_strcasecmp(conn->ctx->config[ENABLE_DIRECTORY_LISTING], "yes")) {
+                handle_directory_request(conn, path);
+            } else {
+                send_http_error(conn, 403, "Directory Listing Denied",
+                    "Directory listing denied");
+            }
+        } else {
+            handle_static_file_request(conn, path, &file);
+        }
     } else {
         send_http_error(conn, 404, "Not Found", "%s", "File not found");
     }