From b55c3f684885020cc19e1c3870aa38624007d423 Mon Sep 17 00:00:00 2001 From: Tim Date: Sun, 8 Aug 2021 10:19:33 +1000 Subject: [PATCH] Fix issue #5506 "WebServer serveStatic () can cause LoadProhibited exception in _svfprintf_r" "Using a Core Debug Level of Verbose and the WebServer serveStatic() function with the default value of nullptr for its cache_header argument, results in a LoadProhibited exception in _svfprintf_r(). This is because serveStatic() calls log_v() with cache_header corresponding to a "%s" in its format but without checking that cache_header is not nullptr, and then logv() (indirectly) calls _svfprintf_r(). On the other hand, with a Core Debug Level other than Verbose, this does not occur." Changed serveStatic() to the check value of cache_header and if it is nullptr, instead pass an empty string to log_v(). --- libraries/WebServer/src/detail/RequestHandlersImpl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/WebServer/src/detail/RequestHandlersImpl.h b/libraries/WebServer/src/detail/RequestHandlersImpl.h index 27a2a8d328a..699015746b3 100644 --- a/libraries/WebServer/src/detail/RequestHandlersImpl.h +++ b/libraries/WebServer/src/detail/RequestHandlersImpl.h @@ -69,7 +69,7 @@ class StaticRequestHandler : public RequestHandler { , _cache_header(cache_header) { _isFile = fs.exists(path); - log_v("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header); + log_v("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header ? cache_header : ""); // issue 5506 - cache_header can be nullptr _baseUriLength = _uri.length(); }