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

[xen staging] tools/xl: check return of json_object_object_add()



commit a4d92cf18955dfd8eb0b9c858a149e064e8e2e54
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Wed Oct 15 14:11:39 2025 +0200
Commit:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
CommitDate: Thu Oct 16 17:20:27 2025 +0200

    tools/xl: check return of json_object_object_add()
    
    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>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
    Release-Acked-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
---
 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;
+
 
+    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;
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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