]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Address side effects of accessing vars via index
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Wed, 11 Jan 2012 11:42:37 +0000 (06:42 -0500)
committerStefan Berger <stefanb@us.ibm.com>
Wed, 11 Jan 2012 11:42:37 +0000 (06:42 -0500)
Address side effect of accessing a variable via an index: Filters
accessing a variable where an element is accessed that is beyond the
size of the list (for example $TEST[10] and only 2 elements are available)
cannot instantiate that filter. Test for this and report proper error
to user.

src/conf/nwfilter_params.c
src/conf/nwfilter_params.h
src/libvirt_private.syms
src/nwfilter/nwfilter_gentech_driver.c

index 592bcd9e3b390ac9513f7db8a5b599b973ac9090..8949b95577c95a136702ae15aa6a0afe3b6763b8 100644 (file)
@@ -1072,3 +1072,32 @@ virNWFilterVarAccessGetIntIterId(const virNWFilterVarAccessPtr vap)
 {
     return vap->u.index.intIterId;
 }
+
+bool
+virNWFilterVarAccessIsAvailable(const virNWFilterVarAccessPtr varAccess,
+                                const virNWFilterHashTablePtr hash)
+{
+    const char *varName = virNWFilterVarAccessGetVarName(varAccess);
+    const char *res;
+    unsigned int idx;
+    virNWFilterVarValuePtr varValue;
+
+    varValue = virHashLookup(hash->hashTable, varName);
+    if (!varValue)
+        return false;
+
+    switch (virNWFilterVarAccessGetType(varAccess)) {
+    case VIR_NWFILTER_VAR_ACCESS_ELEMENT:
+        idx = virNWFilterVarAccessGetIndex(varAccess);
+        res = virNWFilterVarValueGetNthValue(varValue, idx);
+        if (res == NULL)
+            return false;
+        break;
+    case VIR_NWFILTER_VAR_ACCESS_ITERATOR:
+        break;
+    case VIR_NWFILTER_VAR_ACCESS_LAST:
+        return false;
+    }
+
+    return true;
+}
index 68d3d3e0ecd7e90e3ec5856e77179e31effb279e..fa8f770f232e5ef8e555a8b473f3bbf1177f16df 100644 (file)
@@ -125,7 +125,8 @@ enum virNWFilterVarAccessType virNWFilterVarAccessGetType(
                                            const virNWFilterVarAccessPtr vap);
 unsigned int virNWFilterVarAccessGetIterId(const virNWFilterVarAccessPtr vap);
 unsigned int virNWFilterVarAccessGetIndex(const virNWFilterVarAccessPtr vap);
-
+bool virNWFilterVarAccessIsAvailable(const virNWFilterVarAccessPtr vap,
+                                     const virNWFilterHashTablePtr hash);
 
 typedef struct _virNWFilterVarCombIterEntry virNWFilterVarCombIterEntry;
 typedef virNWFilterVarCombIterEntry *virNWFilterVarCombIterEntryPtr;
index 0abce7052af1de75413ba2d844400ad86eb83a05..ca4beb1255302c417383ea2d287bfe0cfe6cf37c 100644 (file)
@@ -833,6 +833,8 @@ virNWFilterHashTablePut;
 virNWFilterHashTablePutAll;
 virNWFilterHashTableRemoveEntry;
 virNWFilterVarAccessGetVarName;
+virNWFilterVarAccessIsAvailable;
+virNWFilterVarAccessPrint;
 virNWFilterVarCombIterCreate;
 virNWFilterVarCombIterFree;
 virNWFilterVarCombIterGetVarValue;
index fe9a3a7e13219bf7dc7b42d1444e7484635463a1..17fdd39ff05a12ae8e7ba23964410b85975ff1fa 100644 (file)
@@ -501,16 +501,29 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
         if (rule) {
             /* check all variables of this rule */
             for (j = 0; j < rule->nVarAccess; j++) {
-                const char *varName;
-                varName = virNWFilterVarAccessGetVarName(rule->varAccess[j]);
-                if (!virHashLookup(vars->hashTable, varName)) {
+                if (!virNWFilterVarAccessIsAvailable(rule->varAccess[j],
+                                                     vars)) {
+                    const char *varAccess;
+                    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+                    virNWFilterVarAccessPrint(rule->varAccess[j], &buf);
+                    if (virBufferError(&buf)) {
+                        virReportOOMError();
+                        rc = -1;
+                        break;
+                    }
+
                     val = virNWFilterVarValueCreateSimpleCopyValue("1");
                     if (!val) {
+                        virBufferFreeAndReset(&buf);
                         rc = -1;
                         break;
                     }
-                    virNWFilterHashTablePut(missing_vars, varName,
+
+                    varAccess = virBufferContentAndReset(&buf);
+                    virNWFilterHashTablePut(missing_vars, varAccess,
                                             val, 1);
+                    VIR_FREE(varAccess);
                 }
             }
             if (rc)
@@ -752,7 +765,7 @@ err_unresolvable_vars:
     if (buf) {
         virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
                    _("Cannot instantiate filter due to unresolvable "
-                     "variables: %s"), buf);
+                     "variables or unavailable list elements: %s"), buf);
         VIR_FREE(buf);
     }