[ovs-dev] [PATCH 2/3] condition: Reject <, <=, >=, > with optional scalar against empty set.

Ben Pfaff blp at ovn.org
Fri Sep 7 02:30:11 UTC 2018


When relational comparisons against optional scalars were introduced, it
was meant to work only when the right-hand side of the comparison was a
scalar, not the empty set.  The implementation wasn't that picky.  This
commit fixes the problem.

CC: Terry Wilson <twilson at redhat.com>
Fixes: 09e256031a62 ("ovsdb: Allow comparison on optional scalar types")
Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 Documentation/ref/ovsdb-server.7.rst |   7 +-
 ovsdb/condition.c                    |   5 +
 tests/ovsdb-condition.at             | 256 ++++++++++++++++++++++++++++++++++-
 3 files changed, 264 insertions(+), 4 deletions(-)

diff --git a/Documentation/ref/ovsdb-server.7.rst b/Documentation/ref/ovsdb-server.7.rst
index 22b335bab1c3..14c7da8e9449 100644
--- a/Documentation/ref/ovsdb-server.7.rst
+++ b/Documentation/ref/ovsdb-server.7.rst
@@ -455,9 +455,10 @@ form::
 For <condition>, RFC 7047 only allows the use of ``!=``, ``==``, ``includes``,
 and ``excludes`` operators with set types.  Open vSwitch 2.4 and later extend
 <condition> to allow the use of ``<``, ``<=``, ``>=``, and ``>`` operators with
-columns with type "set of 0 or 1 integer" and "set of 0 or 1 real".  These
-conditions evaluate to false when the column is empty, and otherwise as
-described in RFC 7047 for integer and real types.
+a column with type "set of 0 or 1 integer" and an integer argument, and with
+"set of 0 or 1 real" and a real argument.  These conditions evaluate to false
+when the column is empty, and otherwise as described in RFC 7047 for integer
+and real types.
 
 <condition> is specified in Section 5.1 in the RFC with the following change: A
 condition can be either a 3-element JSON array as described in the RFC or a
diff --git a/ovsdb/condition.c b/ovsdb/condition.c
index 06126d2922e0..692c0932864c 100644
--- a/ovsdb/condition.c
+++ b/ovsdb/condition.c
@@ -125,7 +125,12 @@ ovsdb_clause_from_json(const struct ovsdb_table_schema *ts,
             free(s);
             return error;
         }
+
+        /* Force the argument to be a scalar. */
+        type.n_min = 1;
+
         break;
+
     case OVSDB_F_EQ:
     case OVSDB_F_NE:
         break;
diff --git a/tests/ovsdb-condition.at b/tests/ovsdb-condition.at
index 58ff32ebbb16..4dee5f9530d5 100644
--- a/tests/ovsdb-condition.at
+++ b/tests/ovsdb-condition.at
@@ -92,7 +92,58 @@ AT_CHECK([[test-ovsdb parse-conditions \
     '[["u", ">", ["uuid", "b10d28f7-af18-4a67-9e78-2a6394516c59"]]]' \
     '[["u", ">=", ["uuid", "9179ca6d-6d65-400a-b455-3ad92783a099"]]]' \
     '[["u", "<", ["uuid", "ad0fa355-8b84-4a36-a4b5-b2c1bfd91758"]]]' \
-    '[["u", "<=", ["uuid", "62315898-64e0-40b9-b26f-ff74225303e6"]]]']],
+    '[["u", "<=", ["uuid", "62315898-64e0-40b9-b26f-ff74225303e6"]]]' \
+    '[["i", "==", ["set", []]]]' \
+    '[["i", "!=", ["set", []]]]' \
+    '[["i", ">", ["set", []]]]' \
+    '[["i", ">=", ["set", []]]]' \
+    '[["i", "<", ["set", []]]]' \
+    '[["i", "<=", ["set", []]]]' \
+    '[["i", "includes", ["set", []]]]' \
+    '[["i", "excludes", ["set", []]]]' \
+    '[["i", ">", ["set", []]]]' \
+    '[["i", "==", ["set", []]]]' \
+    '[["r", "==", ["set", []]]]' \
+    '[["r", "!=", ["set", []]]]' \
+    '[["r", ">", ["set", []]]]' \
+    '[["r", ">=", ["set", []]]]' \
+    '[["r", "<", ["set", []]]]' \
+    '[["r", "<=", ["set", []]]]' \
+    '[["r", "includes", ["set", []]]]' \
+    '[["r", "excludes", ["set", []]]]' \
+    '[["r", ">", ["set", []]]]' \
+    '[["r", "==", ["set", []]]]' \
+    '[["b", "==", ["set", []]]]' \
+    '[["b", "!=", ["set", []]]]' \
+    '[["b", ">", ["set", []]]]' \
+    '[["b", ">=", ["set", []]]]' \
+    '[["b", "<", ["set", []]]]' \
+    '[["b", "<=", ["set", []]]]' \
+    '[["b", "includes", ["set", []]]]' \
+    '[["b", "excludes", ["set", []]]]' \
+    '[["b", ">", ["set", []]]]' \
+    '[["b", "==", ["set", []]]]' \
+    '[["s", "==", ["set", []]]]' \
+    '[["s", "!=", ["set", []]]]' \
+    '[["s", ">", ["set", []]]]' \
+    '[["s", ">=", ["set", []]]]' \
+    '[["s", "<", ["set", []]]]' \
+    '[["s", "<=", ["set", []]]]' \
+    '[["s", "includes", ["set", []]]]' \
+    '[["s", "excludes", ["set", []]]]' \
+    '[["s", ">", ["set", []]]]' \
+    '[["s", "==", ["set", []]]]' \
+    '[["u", "==", ["set", []]]]' \
+    '[["u", "!=", ["set", []]]]' \
+    '[["u", ">", ["set", []]]]' \
+    '[["u", ">=", ["set", []]]]' \
+    '[["u", "<", ["set", []]]]' \
+    '[["u", "<=", ["set", []]]]' \
+    '[["u", "includes", ["set", []]]]' \
+    '[["u", "excludes", ["set", []]]]' \
+    '[["u", ">", ["set", []]]]' \
+    '[["u", "==", ["set", []]]]' \
+]],
   [1], [],
   [[test-ovsdb: syntax "["b",">",true]": syntax error: Type mismatch: ">" operator may not be applied to column b of type boolean.
 test-ovsdb: syntax "["b",">=",false]": syntax error: Type mismatch: ">=" operator may not be applied to column b of type boolean.
@@ -106,6 +157,209 @@ test-ovsdb: syntax "["u",">",["uuid","b10d28f7-af18-4a67-9e78-2a6394516c59"]]":
 test-ovsdb: syntax "["u",">=",["uuid","9179ca6d-6d65-400a-b455-3ad92783a099"]]": syntax error: Type mismatch: ">=" operator may not be applied to column u of type uuid.
 test-ovsdb: syntax "["u","<",["uuid","ad0fa355-8b84-4a36-a4b5-b2c1bfd91758"]]": syntax error: Type mismatch: "<" operator may not be applied to column u of type uuid.
 test-ovsdb: syntax "["u","<=",["uuid","62315898-64e0-40b9-b26f-ff74225303e6"]]": syntax error: Type mismatch: "<=" operator may not be applied to column u of type uuid.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["b",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column b of type boolean.
+test-ovsdb: syntax "["b",">=",["set",[]]]": syntax error: Type mismatch: ">=" operator may not be applied to column b of type boolean.
+test-ovsdb: syntax "["b","<",["set",[]]]": syntax error: Type mismatch: "<" operator may not be applied to column b of type boolean.
+test-ovsdb: syntax "["b","<=",["set",[]]]": syntax error: Type mismatch: "<=" operator may not be applied to column b of type boolean.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["b",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column b of type boolean.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["s",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column s of type string.
+test-ovsdb: syntax "["s",">=",["set",[]]]": syntax error: Type mismatch: ">=" operator may not be applied to column s of type string.
+test-ovsdb: syntax "["s","<",["set",[]]]": syntax error: Type mismatch: "<" operator may not be applied to column s of type string.
+test-ovsdb: syntax "["s","<=",["set",[]]]": syntax error: Type mismatch: "<=" operator may not be applied to column s of type string.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["s",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column s of type string.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["u",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column u of type uuid.
+test-ovsdb: syntax "["u",">=",["set",[]]]": syntax error: Type mismatch: ">=" operator may not be applied to column u of type uuid.
+test-ovsdb: syntax "["u","<",["set",[]]]": syntax error: Type mismatch: "<" operator may not be applied to column u of type uuid.
+test-ovsdb: syntax "["u","<=",["set",[]]]": syntax error: Type mismatch: "<=" operator may not be applied to column u of type uuid.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["u",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column u of type uuid.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+]])
+AT_CLEANUP
+
+OVSDB_CHECK_POSITIVE([conditions on optional scalars],
+  [[parse-conditions \
+    '{"columns":
+        {"i": {"type": {"key": "integer", "min": 0, "max": 1}},
+         "r": {"type": {"key": "real", "min": 0, "max": 1}},
+         "b": {"type": {"key": "boolean", "min": 0, "max": 1}},
+         "s": {"type": {"key": "string", "min": 0, "max": 1}},
+         "u": {"type": {"key": "uuid", "min": 0, "max": 1}}}}' \
+    '[["i", "==", 0]]' \
+    '[["i", "!=", 1]]' \
+    '[["i", "<", 2]]' \
+    '[["i", "<=", 3]]' \
+    '[["i", ">", 4]]' \
+    '[["i", ">=", 5]]' \
+    '[["i", "includes", 6]]' \
+    '[["i", "excludes", 7]]' \
+    '[["r", "==", 0.5]]' \
+    '[["r", "!=", 1.5]]' \
+    '[["r", "<", 2.5]]' \
+    '[["r", "<=", 3.5]]' \
+    '[["r", ">", 4.5]]' \
+    '[["r", ">=", 5.5]]' \
+    '[["r", "includes", 6.5]]' \
+    '[["r", "excludes", 7.5]]' \
+    '[["b", "==", true]]' \
+    '[["b", "!=", false]]' \
+    '[["b", "includes", false]]' \
+    '[["b", "excludes", true]]' \
+    '[["s", "==", "a"]]' \
+    '[["s", "!=", "b"]]' \
+    '[["s", "includes", "c"]]' \
+    '[["s", "excludes", "d"]]' \
+    '[["u", "==", ["uuid", "b10d28f7-af18-4a67-9e78-2a6394516c59"]]]' \
+    '[["u", "!=", ["uuid", "9179ca6d-6d65-400a-b455-3ad92783a099"]]]' \
+    '[["u", "includes", ["uuid", "ad0fa355-8b84-4a36-a4b5-b2c1bfd91758"]]]' \
+    '[["u", "excludes", ["uuid", "62315898-64e0-40b9-b26f-ff74225303e6"]]]']],
+  [[[["i","==",0]]
+[["i","!=",1]]
+[["i","<",2]]
+[["i","<=",3]]
+[["i",">",4]]
+[["i",">=",5]]
+[["i","includes",6]]
+[["i","excludes",7]]
+[["r","==",0.5]]
+[["r","!=",1.5]]
+[["r","<",2.5]]
+[["r","<=",3.5]]
+[["r",">",4.5]]
+[["r",">=",5.5]]
+[["r","includes",6.5]]
+[["r","excludes",7.5]]
+[["b","==",true]]
+[["b","!=",false]]
+[["b","includes",false]]
+[["b","excludes",true]]
+[["s","==","a"]]
+[["s","!=","b"]]
+[["s","includes","c"]]
+[["s","excludes","d"]]
+[["u","==",["uuid","b10d28f7-af18-4a67-9e78-2a6394516c59"]]]
+[["u","!=",["uuid","9179ca6d-6d65-400a-b455-3ad92783a099"]]]
+[["u","includes",["uuid","ad0fa355-8b84-4a36-a4b5-b2c1bfd91758"]]]
+[["u","excludes",["uuid","62315898-64e0-40b9-b26f-ff74225303e6"]]]]],
+  [condition])
+
+AT_SETUP([disallowed conditions on optional scalars])
+AT_KEYWORDS([ovsdb negative condition])
+AT_CHECK([[test-ovsdb parse-conditions \
+    '{"columns":
+        {"i": {"type": {"key": "integer", "min": 0, "max": 1}},
+         "r": {"type": {"key": "real", "min": 0, "max": 1}},
+         "b": {"type": {"key": "boolean", "min": 0, "max": 1}},
+         "s": {"type": {"key": "string", "min": 0, "max": 1}},
+         "u": {"type": {"key": "uuid", "min": 0, "max": 1}}}}' \
+    '[["b", ">", true]]' \
+    '[["b", ">=", false]]' \
+    '[["b", "<", false]]' \
+    '[["b", "<=", false]]' \
+    '[["s", ">", "a"]]' \
+    '[["s", ">=", "b"]]' \
+    '[["s", "<", "c"]]' \
+    '[["s", "<=", "d"]]' \
+    '[["u", ">", ["uuid", "b10d28f7-af18-4a67-9e78-2a6394516c59"]]]' \
+    '[["u", ">=", ["uuid", "9179ca6d-6d65-400a-b455-3ad92783a099"]]]' \
+    '[["u", "<", ["uuid", "ad0fa355-8b84-4a36-a4b5-b2c1bfd91758"]]]' \
+    '[["u", "<=", ["uuid", "62315898-64e0-40b9-b26f-ff74225303e6"]]]' \
+    '[["i", ">", ["set", []]]]' \
+    '[["i", ">=", ["set", []]]]' \
+    '[["i", "<", ["set", []]]]' \
+    '[["i", "<=", ["set", []]]]' \
+    '[["i", ">", ["set", []]]]' \
+    '[["r", ">", ["set", []]]]' \
+    '[["r", ">=", ["set", []]]]' \
+    '[["r", "<", ["set", []]]]' \
+    '[["r", "<=", ["set", []]]]' \
+    '[["r", ">", ["set", []]]]' \
+    '[["b", ">", ["set", []]]]' \
+    '[["b", ">=", ["set", []]]]' \
+    '[["b", "<", ["set", []]]]' \
+    '[["b", "<=", ["set", []]]]' \
+    '[["b", ">", ["set", []]]]' \
+    '[["s", ">", ["set", []]]]' \
+    '[["s", ">=", ["set", []]]]' \
+    '[["s", "<", ["set", []]]]' \
+    '[["s", "<=", ["set", []]]]' \
+    '[["s", ">", ["set", []]]]' \
+    '[["u", ">", ["set", []]]]' \
+    '[["u", ">=", ["set", []]]]' \
+    '[["u", "<", ["set", []]]]' \
+    '[["u", "<=", ["set", []]]]' \
+    '[["u", ">", ["set", []]]]' \
+]],
+  [1], [], [[test-ovsdb: syntax "["b",">",true]": syntax error: Type mismatch: ">" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b",">=",false]": syntax error: Type mismatch: ">=" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b","<",false]": syntax error: Type mismatch: "<" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b","<=",false]": syntax error: Type mismatch: "<=" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["s",">","a"]": syntax error: Type mismatch: ">" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s",">=","b"]": syntax error: Type mismatch: ">=" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s","<","c"]": syntax error: Type mismatch: "<" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s","<=","d"]": syntax error: Type mismatch: "<=" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["u",">",["uuid","b10d28f7-af18-4a67-9e78-2a6394516c59"]]": syntax error: Type mismatch: ">" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u",">=",["uuid","9179ca6d-6d65-400a-b455-3ad92783a099"]]": syntax error: Type mismatch: ">=" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u","<",["uuid","ad0fa355-8b84-4a36-a4b5-b2c1bfd91758"]]": syntax error: Type mismatch: "<" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u","<=",["uuid","62315898-64e0-40b9-b26f-ff74225303e6"]]": syntax error: Type mismatch: "<=" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["set",[]]": syntax error: set must have 1 to 1 members but 0 are present
+test-ovsdb: syntax "["b",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b",">=",["set",[]]]": syntax error: Type mismatch: ">=" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b","<",["set",[]]]": syntax error: Type mismatch: "<" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b","<=",["set",[]]]": syntax error: Type mismatch: "<=" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["b",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column b of type set of up to 1 booleans.
+test-ovsdb: syntax "["s",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s",">=",["set",[]]]": syntax error: Type mismatch: ">=" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s","<",["set",[]]]": syntax error: Type mismatch: "<" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s","<=",["set",[]]]": syntax error: Type mismatch: "<=" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["s",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column s of type set of up to 1 strings.
+test-ovsdb: syntax "["u",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u",">=",["set",[]]]": syntax error: Type mismatch: ">=" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u","<",["set",[]]]": syntax error: Type mismatch: "<" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u","<=",["set",[]]]": syntax error: Type mismatch: "<=" operator may not be applied to column u of type set of up to 1 uuids.
+test-ovsdb: syntax "["u",">",["set",[]]]": syntax error: Type mismatch: ">" operator may not be applied to column u of type set of up to 1 uuids.
 ]])
 AT_CLEANUP
 
-- 
2.16.1



More information about the dev mailing list