You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 340c93f
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Fix request processing failures caused by failed allocations (#501)
* Fix request processing failures caused by failed allocations
Abort the request instead of crashing, corrupting the wire format or
silently mis-parsing it when a heap allocation fails.
Arduino String leaves a failed string empty, and its c_str() is null on
ESP32. Sites that copied header or body data and then passed c_str() to
C string functions could crash (issue #500), and sites that stored the
copy in request state silently lost or corrupted data.
Header parsing:
- Add AsyncWebHeader::tryParse() reporting ParseStatus::NoMemory so a
failed name/value copy fails the request instead of dropping the header
(a lost Content-Length desynchronizes the body parser).
- Scan Accept and Transfer-Encoding in place: the lowercased copies are
gone, so issue #500 cannot happen and chunked framing is no longer
silently missed.
- Abort on failed copies into _host, _contentType, _authorization and on
failed header-line/body accumulation in the plain and multipart parsers.
- Write the 100-continue reply from the literal: the String copy exceeded
the small-buffer size and an OOM one silently stalled the client.
Responses:
- Check every concat() in _assembleHead(); callers now close the
connection instead of writing a truncated head (basic, abstract,
WebSocket and SSE responses).
- AsyncWebSocketResponse flags RESPONSE_FAILED when it cannot build
Sec-WebSocket-Accept, and _sourceValid() reflects it, so the upgrade is
refused rather than completing with a garbage accept header.
Allocation helpers:
- Use std::nothrow for response objects created by beginResponse*(),
AsyncStaticWebHandler and AsyncEventSource so failures are observable
instead of aborting the device; send()/_send() handle a null response.
- Replace plain new with malloc in generateBasicHash() and the WebSocket
printf helpers, where the null checks were dead code.
Static file handler:
- Stop and fall through to 404 when the path cannot be built, rather than
serving the default or a wrong file.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* _assembleHead return false if allocation failed
* Switch to base64_encode_block
* Introduc request->failWithRawResponse(); to fail a request with a custom raw response
* failWithRawResponse => sendRawResponse
* Improve AsyncWebHeader parsing status usign SSO buffer
* Fix usage of asyncsrv::T_HTTP_503_HEAD in sendRawResponse calls
* AsyncWebHeader(String name, String value) : _name(std::move(name)), _value(std::move(value)) {}
* abort() => sendRawResponse()
* Remove strlen()
* Fail the parse in sendRawResponse() and abort()
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Reply to header parse failures from _onData
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Don't run the handler after a chunked encoding error
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Stop multipart parsing by return value after a raw response
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Reply to plain body parse failures from _onData
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Stop parsing when a body or upload handler ends the request
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Don't search for the default file after a raw response
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Stop dispatch when canHandle() ends the request
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Don't leak a response sent after the request has ended
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Return the raw response from the multipart parser
_parseLine returns REQUEST_ENDED too when canHandle() ends the request.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Drop PARSE_REQ_FAIL in favour of PARSE_REQ_END
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fix error return on request parse failure
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Will Miles <will@willmiles.net>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
0 commit comments