Detect string length overflows

This commit is contained in:
Benoit Blanchon
2023-10-09 11:58:02 +02:00
parent 9b34069a3b
commit 6fe4b9c01d
5 changed files with 67 additions and 6 deletions

View File

@ -101,3 +101,20 @@ TEST_CASE("deserializeJson() returns EmptyInput") {
REQUIRE(err == DeserializationError::EmptyInput);
}
}
TEST_CASE("deserializeJson() returns NoMemory if string length overflows") {
JsonDocument doc;
auto maxLength = ArduinoJson::detail::StringNode::maxLength;
SECTION("max length should succeed") {
auto err = deserializeJson(doc, "\"" + std::string(maxLength, 'a') + "\"");
REQUIRE(err == DeserializationError::Ok);
}
SECTION("one above max length should fail") {
auto err =
deserializeJson(doc, "\"" + std::string(maxLength + 1, 'a') + "\"");
REQUIRE(err == DeserializationError::NoMemory);
}
}