Skip to content

Commit

Permalink
Fix crash on AsyncWebServerRequest::_removeNotInterestingHeaders(), c…
Browse files Browse the repository at this point in the history
…aused by deletion from the linked list while looping.
  • Loading branch information
blackhack committed Oct 16, 2023
1 parent c7fb6c5 commit 139a97a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/WebRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 139a97a

Please sign in to comment.