From 291bc6bca518f15663148497e5c1d39e0d6729c3 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Sat, 10 Feb 2018 08:12:38 -0800 Subject: [PATCH] Wrap mimetype strings in FSPTR()s (#4338) Mimetype is now in progmem, so any accesses to it need to be using FPSTR() wrapped Strings. Fixes #4329 --- libraries/ESP8266WebServer/src/ESP8266WebServer.cpp | 10 +++++----- .../ESP8266WebServer/src/detail/RequestHandlersImpl.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 4eef8725a..ff7c58dfa 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -195,7 +195,7 @@ bool ESP8266WebServer::authenticate(const char * username, const char * password #endif md5.begin(); if(authReq.indexOf(FPSTR(qop_auth)) != -1) { - md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _nc + FPSTR(colon) + _cnonce + ':auth:' + _H2); + md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _nc + FPSTR(colon) + _cnonce + ":auth:" + _H2); }else{ md5.add(_H1 + FPSTR(colon) + _nonce + FPSTR(colon) + _H2); } @@ -376,7 +376,7 @@ void ESP8266WebServer::_prepareHeader(String& response, int code, const char* co if (!content_type) content_type = mimeTable[html].mimeType; - sendHeader(String(F("Content-Type")), content_type, true); + sendHeader(String(F("Content-Type")), String(FPSTR(content_type)), true); if (_contentLength == CONTENT_LENGTH_NOT_SET) { sendHeader(String(FPSTR(Content_Length)), String(contentLength)); } else if (_contentLength != CONTENT_LENGTH_UNKNOWN) { @@ -485,9 +485,9 @@ void ESP8266WebServer::_streamFileCore(const size_t fileSize, const String & fil { using namespace mime; setContentLength(fileSize); - if (fileName.endsWith(mimeTable[gz].endsWith) && - contentType != mimeTable[gz].mimeType && - contentType != mimeTable[none].mimeType) { + if (fileName.endsWith(String(FPSTR(mimeTable[gz].endsWith))) && + contentType != String(FPSTR(mimeTable[gz].mimeType)) && + contentType != String(FPSTR(mimeTable[none].mimeType))) { sendHeader(F("Content-Encoding"), F("gzip")); } send(200, contentType, ""); diff --git a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h index b1de4a600..63f033999 100644 --- a/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h @@ -3,6 +3,7 @@ #include "RequestHandler.h" #include "mimetable.h" +#include "WString.h" using namespace mime; @@ -101,10 +102,10 @@ public: // look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for // if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc... - if (!path.endsWith(mimeTable[gz].endsWith) && !_fs.exists(path)) { - String pathWithGz = path + mimeTable[gz].endsWith; + if (!path.endsWith(FPSTR(mimeTable[gz].endsWith)) && !_fs.exists(path)) { + String pathWithGz = path + FPSTR(mimeTable[gz].endsWith); if(_fs.exists(pathWithGz)) - path += mimeTable[gz].endsWith; + path += FPSTR(mimeTable[gz].endsWith); } File f = _fs.open(path, "r");