[PATCH 2/2] nwfilter: address more coverity findings

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

 



This patch addresses the following coverity findings:

/libvirt/src/conf/nwfilter_params.c:390:
var_assigned: Assigning: "varValue" = null return value from "virHashLookup".

/libvirt/src/conf/nwfilter_params.c:392:
dereference: Dereferencing a pointer that might be null "varValue" when calling "virNWFilterVarValueGetNthValue".

/libvirt/src/conf/nwfilter_params.c:399:
dereference: Dereferencing a pointer that might be null "tmp" when calling "virNWFilterVarValueGetNthValue".

---
 src/conf/nwfilter_params.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Index: libvirt-acl/src/conf/nwfilter_params.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_params.c
+++ libvirt-acl/src/conf/nwfilter_params.c
@@ -30,7 +30,7 @@
 #include "datatypes.h"
 #include "nwfilter_params.h"
 #include "domain_conf.h"
-
+#include "logging.h"

 #define VIR_FROM_THIS VIR_FROM_NWFILTER

@@ -391,14 +391,28 @@ virNWFilterVarCombIterEntryAreUniqueEntr
     const char *value;

     varValue = virHashLookup(hash->hashTable, cie->varNames[0]);
+    if (!varValue) {
+        /* caller's error */
+        VIR_ERROR(_("%s: hash lookup resulted in NULL pointer"), __func__);
+        return true;
+    }

     value = virNWFilterVarValueGetNthValue(varValue, cie->curValue);
+    if (!value) {
+        VIR_ERROR(_("%s: Lookup of value at index %u resulted in a NULL "
+                  "pointer"), __func__, cie->curValue);
+        return true;
+    }

     for (i = 0; i < cie->curValue; i++) {
         if (STREQ(value, virNWFilterVarValueGetNthValue(varValue, i))) {
             bool isSame = true;
             for (j = 1; j < cie->nVarNames; j++) {
                 tmp = virHashLookup(hash->hashTable, cie->varNames[j]);
+                if (!tmp) {
+                    /* should never occur to step on a NULL here */
+                    return true;
+                }
if (!STREQ(virNWFilterVarValueGetNthValue(tmp, cie->curValue),
                            virNWFilterVarValueGetNthValue(tmp, i))) {
                     isSame = false;

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


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