util: json: Report non-OOM error on yajl failure

The yajl library returns a wide range of error codes so reporting OOM on
any failure is wrong. In case the error was really based by memory issue
the error reporting will probably cause an abort anyways. Change the
error message so that we know that it happened in JSON at least.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-24 10:13:27 +01:00
parent e09c852782
commit 0af84a81fc

View File

@ -1943,12 +1943,14 @@ virJSONValueToBuffer(virJSONValuePtr object,
yajl_gen_config(g, yajl_gen_validate_utf8, 1);
if (virJSONValueToStringOne(object, g) < 0) {
virReportOOMError();
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to convert virJSONValue to yajl data"));
goto cleanup;
}
if (yajl_gen_get_buf(g, &str, &len) != yajl_gen_status_ok) {
virReportOOMError();
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to format JSON"));
goto cleanup;
}