[libvirt PATCH] conf: Avoid NULL dereference in virDomainNetPortForwardFree

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

 



In our current code the function is not called with NULL argument, but
we should follow our common practice and make it safe anyway.

Reported by coverity:

    /src/conf/domain_conf.c: 2635 in virDomainNetPortForwardFree()
    2629     {
    2630         size_t i;
    2631
    2632         if (pf)
    2633             g_free(pf->dev);
    2634
    >>>     CID 404359:  Null pointer dereferences  (FORWARD_NULL)
    >>>     Dereferencing null pointer "pf".
    2635         for (i = 0; i < pf->nRanges; i++)
    2636             g_free(pf->ranges[i]);
    2637
    2638         g_free(pf->ranges);
    2639         g_free(pf);
    2640     }

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 598e23b005..e43dee1a60 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2629,8 +2629,10 @@ virDomainNetPortForwardFree(virDomainNetPortForward *pf)
 {
     size_t i;
 
-    if (pf)
-        g_free(pf->dev);
+    if (!pf)
+        return;
+
+    g_free(pf->dev);
 
     for (i = 0; i < pf->nRanges; i++)
         g_free(pf->ranges[i]);
-- 
2.39.0




[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]

  Powered by Linux