From c7fb6c5c9c0d3d9b8bf6c61f096a8dff8a6b39fe Mon Sep 17 00:00:00 2001 From: JDavid Date: Sat, 14 Oct 2023 23:00:11 -0500 Subject: [PATCH 1/2] Fix build on Arduino ESP32 v3.0.0 and IDF 5.1.1 --- src/AsyncEventSource.cpp | 4 ++++ src/AsyncWebSocket.cpp | 11 ++++++----- src/WebAuthentication.cpp | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/AsyncEventSource.cpp b/src/AsyncEventSource.cpp index f2914df54..fec292556 100644 --- a/src/AsyncEventSource.cpp +++ b/src/AsyncEventSource.cpp @@ -20,6 +20,10 @@ #include "Arduino.h" #include "AsyncEventSource.h" +#ifdef ESP32 +#include "rom/ets_sys.h" +#endif + static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect){ String ev = ""; diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp index f76f2fc96..cf4981610 100644 --- a/src/AsyncWebSocket.cpp +++ b/src/AsyncWebSocket.cpp @@ -23,8 +23,9 @@ #include -#ifndef ESP8266 +#ifdef ESP32 #include "mbedtls/sha1.h" +#include "rom/ets_sys.h" #else #include #endif @@ -829,7 +830,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer) IPAddress AsyncWebSocketClient::remoteIP() { if(!_client) { - return IPAddress(0U); + return IPAddress(uint32_t(0)); } return _client->remoteIP(); } @@ -1259,9 +1260,9 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket (String&)key += WS_STR_UUID; mbedtls_sha1_context ctx; mbedtls_sha1_init(&ctx); - mbedtls_sha1_starts_ret(&ctx); - mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length()); - mbedtls_sha1_finish_ret(&ctx, hash); + mbedtls_sha1_starts(&ctx); + mbedtls_sha1_update(&ctx, (const unsigned char*)key.c_str(), key.length()); + mbedtls_sha1_finish(&ctx, hash); mbedtls_sha1_free(&ctx); #endif base64_encodestate _state; diff --git a/src/WebAuthentication.cpp b/src/WebAuthentication.cpp index 45246a196..2feca5420 100644 --- a/src/WebAuthentication.cpp +++ b/src/WebAuthentication.cpp @@ -71,9 +71,9 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo memset(_buf, 0x00, 16); #ifdef ESP32 mbedtls_md5_init(&_ctx); - mbedtls_md5_starts_ret(&_ctx); - mbedtls_md5_update_ret(&_ctx, data, len); - mbedtls_md5_finish_ret(&_ctx, _buf); + mbedtls_md5_starts(&_ctx); + mbedtls_md5_update(&_ctx, data, len); + mbedtls_md5_finish(&_ctx, _buf); #else MD5Init(&_ctx); MD5Update(&_ctx, data, len); From 139a97a72121f6d79ac2320afaf1d6121facb31a Mon Sep 17 00:00:00 2001 From: JDavid Date: Mon, 16 Oct 2023 14:29:45 -0500 Subject: [PATCH 2/2] Fix crash on AsyncWebServerRequest::_removeNotInterestingHeaders(), caused by deletion from the linked list while looping. --- src/WebRequest.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index bbce5ca4c..9975b7487 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -180,10 +180,15 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){ void AsyncWebServerRequest::_removeNotInterestingHeaders(){ if (_interestingHeaders.containsIgnoreCase("ANY")) return; // nothing to do - for(const auto& header: _headers){ - if(!_interestingHeaders.containsIgnoreCase(header->name().c_str())){ + + auto itr = _headers.begin(); + while (itr != _headers.end()) + { + const auto header = *itr; + ++itr; // ++operator before remove(), otherwise itr becomes invalid + + if (!_interestingHeaders.containsIgnoreCase(header->name().c_str())) _headers.remove(header); - } } }