#3136: Fixed null character issue when parsing a JSON

This commit is contained in:
Günter Obiltschnig
2021-04-12 20:28:30 +02:00
parent e4b258765e
commit e577e36c25
2 changed files with 15 additions and 1 deletions

View File

@@ -204,7 +204,12 @@ void ParserImpl::handle()
break;
}
case JSON_STRING:
if (_pHandler) _pHandler->value(std::string(json_get_string(_pJSON, NULL)));
if (_pHandler)
{
std::size_t length = 0;
const char* val = json_get_string(_pJSON, &length);
_pHandler->value(std::string(val, length == 0 ? 0 : length - 1)); // Decrease the length by 1 because it also contains the terminating null character
}
break;
case JSON_OBJECT:
if (_pHandler) _pHandler->startObject();