[PATCH 3/3] virSecurityDeviceLabelDefNew: Avoid NULL dereference

Michal Privoznik posted 3 patches 5 years, 10 months ago
[PATCH 3/3] virSecurityDeviceLabelDefNew: Avoid NULL dereference
Posted by Michal Privoznik 5 years, 10 months ago
While it is impossible for VIR_ALLOC() to return an error, we
should be consistent with the rest of the code and not continue
initializing the virSecurityDeviceLabelDef structure.

Signed-off-by: Michal Privoznik <mprivozn@redhat.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.24.1

Re: [PATCH 3/3] virSecurityDeviceLabelDefNew: Avoid NULL dereference
Posted by Daniel P. Berrangé 5 years, 10 months ago
On Mon, Mar 30, 2020 at 11:25:00AM +0200, Michal Privoznik wrote:
> While it is impossible for VIR_ALLOC() to return an error, we
> should be consistent with the rest of the code and not continue
> initializing the virSecurityDeviceLabelDef structure.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/util/virseclabel.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|