[PATCH] examples: check asprintf return value in client_info.c

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

 



On error, asprintf returns -1 and the contents of the string
pointer is undefined. In the rest of the libvirt code,
the virAsprintf wrapper takes care of that.

Check the return value and report a generic error, since we
purposefully avoid linking to virutil.
---
 examples/admin/client_info.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/examples/admin/client_info.c b/examples/admin/client_info.c
index dd0a04a..314a090 100644
--- a/examples/admin/client_info.c
+++ b/examples/admin/client_info.c
@@ -86,6 +86,11 @@ exampleGetTypedParamValue(virTypedParameterPtr item)
         return NULL;
     }
 
+    if (ret < 0) {
+        fprintf(stderr, "error formatting typed param value\n");
+        return NULL;
+    }
+
     return str;
 }
 
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]