8000 Merge pull request #111 from Eloquence4/WebserverCrashFix · rainbowyu/esp32-snippets@4f173d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f173d1

Browse files
authored
Merge pull request nkolban#111 from Eloquence4/WebserverCrashFix
If i opened 192.168.4.1 without any path after, the esp would crash
2 parents 1a30b01 + 9655374 commit 4f173d1

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