[PATCH for-4.21 5/6] tools/xl: fix possible uninitialized usage in printf_info()

Roger Pau Monne posted 6 patches 2 weeks, 1 day ago
[PATCH for-4.21 5/6] tools/xl: fix possible uninitialized usage in printf_info()
Posted by Roger Pau Monne 2 weeks, 1 day ago
printf_info_one_json() won't initialize the passed jso_r parameter on
error, and hence the usage in printf_info() needs prior initialization,
otherwise an uninitialized pointer is passed to json_object_put() on
failure.

Reported by the internal XenServer Coverity instance.

Fixes: f6c6f2679d49 ("libxl: Convert libxl__object_to_json() to json-c")
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 tools/xl/xl_info.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/xl/xl_info.c b/tools/xl/xl_info.c
index 696f1f7423cb..0314ce7d4c22 100644
--- a/tools/xl/xl_info.c
+++ b/tools/xl/xl_info.c
@@ -155,7 +155,7 @@ void printf_info(enum output_format output_format,
 #ifdef HAVE_LIBJSONC
     int r;
     const char *buf;
-    json_object *jso;
+    json_object *jso = NULL;
 
     r = printf_info_one_json(&jso, domid, d_config);
     if (r)
-- 
2.51.0


Re: [PATCH for-4.21 5/6] tools/xl: fix possible uninitialized usage in printf_info()
Posted by Jason Andryuk 2 weeks, 1 day ago
On 2025-10-15 09:40, Roger Pau Monne wrote:
> printf_info_one_json() won't initialize the passed jso_r parameter on
> error, and hence the usage in printf_info() needs prior initialization,
> otherwise an uninitialized pointer is passed to json_object_put() on
> failure.
> 
> Reported by the internal XenServer Coverity instance.
> 
> Fixes: f6c6f2679d49 ("libxl: Convert libxl__object_to_json() to json-c")
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>