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
-
{
123
+
if (request->contentLength() > _maxContentLength) {
125
124
request->send(413);
126
125
return;
127
126
}
128
127
129
128
// 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.
129
+
if (request->_tempObject != NULL) {
130
+
size_t dataSize =
131
+
min(request->contentLength(), request->_tempSize);// smaller value of contentLength or the size of the buffer. normally those should match.
133
132
#if ARDUINOJSON_VERSION_MAJOR == 5
134
133
DynamicJsonBuffer jsonBuffer;
135
-
uint8_t *p = (uint8_t *)(request->_tempObject);
136
-
p[dataSize] = '\0'; // null terminate, assume we allocated one extra char
134
+
uint8_t *p = (uint8_t *)(request->_tempObject);
135
+
p[dataSize] = '\0'; // null terminate, assume we allocated one extra char
137
136
// parse can only get null terminated strings as parameters
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
165
+
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { // if request content length is valid size and we have no content buffer yet
166
+
request->_tempObject = malloc(total + 1); // allocate one additional byte so we can null terminate this buffer (needed for ArduinoJson 5)
167
+
if (request->_tempObject == NULL) { // if allocation failed
169
168
#ifdef ESP32
170
169
log_e("Failed to allocate");
171
170
#endif
172
171
request->abort();
173
172
return;
174
173
}
175
-
request->_tempSize = total; // store the size of allocation we made into _tempSize
174
+
request->_tempSize = total; // store the size of allocation we made into _tempSize
176
175
}
177
176
if (request->_tempObject != NULL) {
178
177
// check if the buffer is the right size so we don't write out of bounds
0 commit comments