[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH for-4.21 3/6] tools/xl: check return of json_object_object_add()


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 15 Oct 2025 15:40:40 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QrHEmkaFLq+k4yjYl1wqBoURqxns2g5ZgZNwc8LrECs=; b=jhvPlop+nWSTPsIqXRx835a6yBU9obCaRtge8y4xwe+e7TSz4gi9BIT2NtJPb4/2urdedp4edzlJjEBkafxxb5biEv/NOOpJxFqrRFt+mqJwRXbnUVudu2hnD0mYPus0kBFynMFcQyWlvudo0OK46c4mgYS0BmqP1ttJC/nuRBre5hydBGw9lKW/WoQc3AO6td/HYP3jLTEOGMVRdP3Aro12+4OB/hK9zp/S11uz708Z/WCCP0mHnADT/zzoW5DdyU5BNdy8xYyULdeU1XCeo4r6nmi/GVx9jf08iLRB31E6D0T6IVJfFSsUwfPsmavDLQuzUJyJWEEaxijlYMtWQw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VBmCzwRurlPgCTPrxdWfalX9AMD34lhya/slimtvZMrPuC/kWApROARAPYDqg08kYQx11UakbCmd+DVng9P0byep24LA2tRWo30znPB4Gjrk0SSw43tXJhTylKwLlIyC3UGzH03frLre8/SnG5++k47Ef7dLmnPZFkNSTqa72ZRKb3qRk3DscHBDO2mS0ZClOnlzsRSzYcZv+Q5It95nntCiaLJrbgd8NUoOlgQ/ch5/0MAIwT0eFl44rVva/RtKLay15X5gBZMzO0eYr1W4fPLczgC4F7m4RYuCY9KKaSinOBzKb1JY4fr9RAuMBII9Up3Zni3Lx/c/d8oyL4unOg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: oleksii.kurochko@xxxxxxxxx, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Wed, 15 Oct 2025 13:48:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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é <roger.pau@xxxxxxxxxx>
---
 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 777ff2c64294..2048669abbd4 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_success;
     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);
@@ -82,12 +82,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;
+
 
+    rc = json_object_object_add(jso, "config", jso_config);
+    if (rc)
+        goto out;
 
-    json_object_object_add(jso, "config", jso_config);
     jso_config = NULL;
 
     *jso_r = jso;
-- 
2.51.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.