Browse Source

mg_send_file fails unchecked if called with a directory name

bel 10 years ago
parent
commit
e162202932
1 changed files with 10 additions and 1 deletions
  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");
     }