[libvirt] [PATCH 2/3] xen: Check return value of virStringReplace

Michal Privoznik mprivozn at redhat.com
Tue Feb 23 08:49:08 UTC 2016


After 6604a3dd9f8 in which new helper function has been
introduced, the code calls virStringReplace and dereference the
result immediately. The string function can, however, return NULL
so this would SIGSEGV right away. Check for the return value of
the string function.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/xenconfig/xen_xl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 585ef9b..e65f5c6 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -254,7 +254,12 @@ xenParseXLDiskSrc(virDomainDiskDefPtr disk, char *srcstr)
     int ret = -1;
 
     if (STRPREFIX(srcstr, "rbd:")) {
-        tmpstr = virStringReplace(srcstr, "\\\\", "\\");
+        if (!(tmpstr = virStringReplace(srcstr, "\\\\", "\\"))) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unable to parse disk source string: %s"),
+                           srcstr);
+            goto cleanup;
+        }
 
         virDomainDiskSetType(disk, VIR_STORAGE_TYPE_NETWORK);
         disk->src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
-- 
2.4.10




More information about the libvir-list mailing list