[libvirt PATCH] conf: Avoid NULL dereference in virDomainNetPortForwardFree

Jiri Denemark posted 1 patch 1 year, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/9615791925e3108ecb7bedfd8a1fa11164e517af.1673426991.git.jdenemar@redhat.com
src/conf/domain_conf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[libvirt PATCH] conf: Avoid NULL dereference in virDomainNetPortForwardFree
Posted by Jiri Denemark 1 year, 3 months ago
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@redhat.com>
---
 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
Re: [libvirt PATCH] conf: Avoid NULL dereference in virDomainNetPortForwardFree
Posted by Pavel Hrdina 1 year, 3 months ago
On Wed, Jan 11, 2023 at 09:49:51AM +0100, Jiri Denemark wrote:
> 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@redhat.com>
> ---
>  src/conf/domain_conf.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>