From a4d92cf18955dfd8eb0b9c858a149e064e8e2e54 Mon Sep 17 00:00:00 2001 From: Roger Pau Monne Date: Wed, 15 Oct 2025 14:11:39 +0200 Subject: [PATCH] tools/xl: check return of json_object_object_add() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check the return codes of json_object_object_add() calls in printf_info_one_json(). Reported by XenServer internal Coverity instance. Fixes: f6c6f2679d49 ("libxl: Convert libxl__object_to_json() to json-c") Signed-off-by: Roger Pau Monné Reviewed-by: Andrew Cooper Reviewed-by: Jason Andryuk Release-Acked-by: Oleksii Kurochko --- tools/xl/xl_info.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c index 47f4bb7e3f..b1799dd8af 100644 --- a/tools/xl/xl_info.c +++ b/tools/xl/xl_info.c @@ -69,7 +69,7 @@ static int printf_info_one_json(json_object **jso_r, int domid, json_object *jso_config = NULL; enum json_tokener_error error = json_tokener_error_parse_unexpected; char *s = NULL; - int r = EXIT_FAILURE; + int r = EXIT_FAILURE, rc; s = libxl_domain_config_to_json(ctx, d_config); jso_config = json_tokener_parse_verbose(s, &error); @@ -81,12 +81,17 @@ static int printf_info_one_json(json_object **jso_r, int domid, jso = json_object_new_object(); if (domid != -1) - json_object_object_add(jso, "domid", json_object_new_int(domid)); + rc = json_object_object_add(jso, "domid", json_object_new_int(domid)); else - json_object_object_add(jso, "domid", json_object_new_null()); + rc = json_object_object_add(jso, "domid", json_object_new_null()); + if (rc) + goto out; - json_object_object_add(jso, "config", jso_config); + rc = json_object_object_add(jso, "config", jso_config); + if (rc) + goto out; + jso_config = NULL; *jso_r = jso;