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
// check if body is too large, if it is, don't parse
123
+
if (request->contentLength() > _maxContentLength)
124
+
{
125
+
request->send(413);
126
+
return;
127
+
}
121
128
129
+
// try to parse body as JSON
130
+
if (request->_tempObject != NULL)
131
+
{
132
+
size_t dataSize = min(request->contentLength(), request->_tempSize); // smaller value of contentLength or the size of the buffer. normally those should match.
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) {
152
-
request->_tempObject = malloc(total);
153
-
if (request->_tempObject == NULL) {
166
+
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { // if request content length is valid size and we have no content buffer yet
167
+
request->_tempObject = malloc(total + 1); // allocate one additional byte so we can null terminate this buffer (needed for ArduinoJson 5)
168
+
if (request->_tempObject == NULL) { // if allocation failed
154
169
#ifdef ESP32
155
170
log_e("Failed to allocate");
156
171
#endif
157
172
request->abort();
158
173
return;
159
174
}
175
+
request->_tempSize = total; // store the size of allocation we made into _tempSize
0 commit comments