Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions examples/ChunkRetryResponse/ChunkRetryResponse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,34 @@ void setup() {
"/api", HTTP_POST,
[](AsyncWebServerRequest *request) {
// request parsing has finished
String *data = (String *)request->_tempObject;

if (!data) {
request->send(400);
return;
}

// no data ?
if (!((String *)request->_tempObject)->length()) {
if (!data->length()) {
delete data;
request->_tempObject = nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if applicable here, but as a rule of thumb, those two lines should be swapped in case that tempObject is accessed in between the lines from another task and we risk use after free

request->send(400);
return;
}

JsonDocument doc;

// deserialize and check for errors
if (deserializeJson(doc, *(String *)request->_tempObject)) {
if (deserializeJson(doc, *data)) {
delete data;
request->_tempObject = nullptr;
request->send(400);
return;
}

delete data;
request->_tempObject = nullptr;

// start UART com: UART will send the data to the Serial console and wait for the key press
triggerUART = doc["input"].as<const char *>();
key = -1;
Expand Down