Skip to content

Commit

Permalink
🐛 Backport fix for issue #178 into master/stable branch (#416)
Browse files Browse the repository at this point in the history
* Backport config parsing fix, a964b78 from upstream

* bodyCharArray no longer exists so do not try to free it
  • Loading branch information
nkaminski authored and marvinroger committed Nov 15, 2017
1 parent dad284b commit f06f111
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Homie/Boot/BootConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ void BootConfig::_onConfigRequest() {
}

StaticJsonBuffer<MAX_JSON_CONFIG_ARDUINOJSON_BUFFER_SIZE> parseJsonBuffer;
char* bodyCharArray = strdup(this->_http.arg("plain").c_str());
JsonObject& parsedJson = parseJsonBuffer.parseObject(bodyCharArray); // do not use plain String, else fails
size_t bodyLength = _http.arg("plain").length();
std::unique_ptr<char[]> bodyString(new char[bodyLength + 1]);
memcpy(bodyString.get(), _http.arg("plain").c_str(), bodyLength);
bodyString.get()[bodyLength] = '\0';
JsonObject& parsedJson = parseJsonBuffer.parseObject(bodyString.get()); // workaround, cannot pass raw String otherwise JSON parsing fails randomly
if (!parsedJson.success()) {
this->_interface->logger->logln(F("✖ Invalid or too big JSON"));
String errorJson = String(FPSTR(PROGMEM_CONFIG_JSON_FAILURE_BEGINNING));
Expand All @@ -174,7 +177,6 @@ void BootConfig::_onConfigRequest() {
}

ConfigValidationResult configValidationResult = Helpers::validateConfig(parsedJson);
free(bodyCharArray);
if (!configValidationResult.valid) {
this->_interface->logger->log(F("✖ Config file is not valid, reason: "));
this->_interface->logger->logln(configValidationResult.reason);
Expand Down

0 comments on commit f06f111

Please sign in to comment.