]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: json: Report non-OOM error on yajl failure
authorPeter Krempa <pkrempa@redhat.com>
Wed, 24 Feb 2021 09:13:27 +0000 (10:13 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 Mar 2021 08:50:20 +0000 (09:50 +0100)
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>
src/util/virjson.c

index e74b9fca4f0231853e762e6d17a569b7c69901d8..f2a6024db6850b633acf6f5a0682dc8135368297 100644 (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;
     }