8000 If i opened 192.168.4.1 without any path after, the esp would crash · rainbowyu/esp32-snippets@9655374 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9655374

Browse files
committed
If i opened 192.168.4.1 without any path after, the esp would crash
This fixes that
1 parent 1a30b01 commit 9655374

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cpp_utils/WebServer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,10 @@ void WebServer::processRequest(struct mg_connection *mgConnection, struct http_m
590590
filePath += httpResponse.getRootPath();
591591
filePath.append(message->uri.p, message->uri.len);
592592
ESP_LOGD(tag, "Opening file: %s", filePath.c_str());
593-
FILE* file = fopen(filePath.c_str(), "rb");
593+
FILE* file = nullptr;
594+
595+
if(strcmp(filePath.c_str(), "/") != 0)
596+
file = fopen(filePath.c_str(), "rb");
594597
if (file != nullptr) {
595598
auto pData = (uint8_t*)malloc(MAX_CHUNK_LENGTH);
596599
size_t read = fread(pData, 1, MAX_CHUNK_LENGTH, file);

0 commit comments

Comments
 (0)
0