Skip to content

Commit 342694b

Browse files
committed
Discard bytes after Content-Length
When accepting an upload, discard any bytes after Content-Length. This ensures that handlers such as AsyncJson can safely allocate the correct sized buffer without needing to additionally check for overrun. Fixes me-no-dev#100
1 parent 2d3af2c commit 342694b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/WebRequest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
156156
// A handler should be already attached at this point in _parseLine function.
157157
// If handler does nothing (_onRequest is NULL), we don't need to really parse the body.
158158
const bool needParse = _handler && !_handler->isRequestHandlerTrivial();
159+
// Discard any bytes after content length; handlers may overrun their buffers
160+
len = std::min(len, _contentLength - _parsedLength);
159161
if(_isMultipart){
160162
if(needParse){
161163
size_t i;

0 commit comments

Comments
 (0)