[libvirt] [PATCH] util: Fix segmentation fault when seclabel fails to allocate memory

jcfaracco at gmail.com jcfaracco at gmail.com
Sat Nov 2 04:28:51 UTC 2019


From: Julio Faracco <jcfaracco at gmail.com>

In function virSecurityDeviceLabelDefNew(), when libvirt fails to
allocate seclabel structure it returns a failure. This case is setting
seclabel as a NULL pointer and accessing its attribute below. This
commit fixes this wrong logic.

Signed-off-by: Julio Faracco <jcfaracco at gmail.com>
---
 src/util/virseclabel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/virseclabel.c b/src/util/virseclabel.c
index a2b5ebf6b7..2141d84210 100644
--- a/src/util/virseclabel.c
+++ b/src/util/virseclabel.c
@@ -77,7 +77,7 @@ virSecurityDeviceLabelDefNew(const char *model)
 
     if (VIR_ALLOC(seclabel) < 0) {
         virSecurityDeviceLabelDefFree(seclabel);
-        seclabel = NULL;
+        return NULL;
     }
 
     seclabel->model = g_strdup(model);
-- 
2.20.1




More information about the libvir-list mailing list