Skip to content

Commit 146faf6

Browse files
committed
WebServer: Fix OOB write
Successful exploitation could lead to arbitrary code execution. The bug can be reproduced by running the following in a browser: ``` const formData = new FormData(); for (let i = 0;i < 33;++i) { formData.append("foo", i.toString()); } await fetch("http://esp.local", { method: 'POST', body: formData }); ```
1 parent b92c58d commit 146faf6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: libraries/WebServer/src/Parsing.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
356356
client.readStringUntil('\n');
357357
//start reading the form
358358
if (line == ("--"+boundary)){
359-
if(_postArgs) delete[] _postArgs;
360-
_postArgs = new RequestArgument[WEBSERVER_MAX_POST_ARGS];
361-
_postArgsLen = 0;
359+
if(_postArgs) delete[] _postArgs;
360+
_postArgs = new RequestArgument[WEBSERVER_MAX_POST_ARGS];
361+
_postArgsLen = 0;
362362
while(1){
363363
String argName;
364364
String argValue;
@@ -406,9 +406,15 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
406406
}
407407
log_v("PostArg Value: %s", argValue.c_str());
408408

409-
RequestArgument& arg = _postArgs[_postArgsLen++];
410-
arg.key = argName;
411-
arg.value = argValue;
409+
if (_postArgsLen >= WEBSERVER_MAX_POST_ARGS) {
410+
// TODO: Forward error to user
411+
// However this library doesn't have any way of forwarding parser errors to users
412+
log_v("Too many PostArgs (max: %d) in request, the rest of the args will be ignored!", WEBSERVER_MAX_POST_ARGS);
413+
} else {
414+
RequestArgument& arg = _postArgs[_postArgsLen++];
415+
arg.key = argName;
416+
arg.value = argValue;
417+
}
412418

413419
if (line == ("--"+boundary+"--")){
414420
log_v("Done Parsing POST");

0 commit comments

Comments
 (0)