浏览代码

Check open mode for files in memory

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

+ 8 - 1
src/civetweb.c

@@ -1954,6 +1954,9 @@ mg_get_valid_options(void)
 }
 }
 
 
 
 
+/* Do not open file (used in is_file_in_memory) */
+#define MG_FOPEN_MODE_NONE (0)
+
 /* Open file for read only access */
 /* Open file for read only access */
 #define MG_FOPEN_MODE_READ (1)
 #define MG_FOPEN_MODE_READ (1)
 
 
@@ -1978,6 +1981,10 @@ open_file_in_memory(const struct mg_connection *conn,
 		return 0;
 		return 0;
 	}
 	}
 
 
+	if ((mode != MG_FOPEN_MODE_NONE) && (mode != MG_FOPEN_MODE_READ)) {
+		return 0;
+	}
+
 	if (conn->ctx->callbacks.open_file) {
 	if (conn->ctx->callbacks.open_file) {
 		buf = conn->ctx->callbacks.open_file(conn, path, &size);
 		buf = conn->ctx->callbacks.open_file(conn, path, &size);
 		if (buf != NULL) {
 		if (buf != NULL) {
@@ -2012,7 +2019,7 @@ open_file_in_memory(const struct mg_connection *conn,
 static int
 static int
 is_file_in_memory(const struct mg_connection *conn, const char *path)
 is_file_in_memory(const struct mg_connection *conn, const char *path)
 {
 {
-	return open_file_in_memory(conn, path, NULL, 0);
+	return open_file_in_memory(conn, path, NULL, MG_FOPEN_MODE_NONE);
 }
 }