Fix SEGV crash caused by Value(s) appended to itself.
Copying such Value(s) causes infinite recursion on `dupPayload` call.
This commit is contained in:
parent
94a6220f7c
commit
897f3d50aa
@ -1128,6 +1128,8 @@ Value& Value::append(const Value& value) { return append(Value(value)); }
|
||||
Value& Value::append(Value&& value) {
|
||||
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue,
|
||||
"in Json::Value::append: requires arrayValue");
|
||||
JSON_ASSERT_MESSAGE(&value != this,
|
||||
"in Json::Value::append: appending self using move constructor is forbidden.");
|
||||
if (type() == nullValue) {
|
||||
*this = Value(arrayValue);
|
||||
}
|
||||
|
@ -2136,6 +2136,10 @@ JSONTEST_FIXTURE_LOCAL(ValueTest, searchValueByPath) {
|
||||
JSONTEST_ASSERT_STRING_EQUAL(expected, outcome);
|
||||
}
|
||||
}
|
||||
JSONTEST_FIXTURE_LOCAL(ValueTest, valueAppendingSelf) {
|
||||
Json::Value value1{Json::ValueType::nullValue}, value2;
|
||||
JSONTEST_ASSERT_THROWS(value2 = value1.append(std::move(value1)));
|
||||
}
|
||||
struct FastWriterTest : JsonTest::TestCase {};
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(FastWriterTest, dropNullPlaceholders) {
|
||||
|
Loading…
Reference in New Issue
Block a user