Skip to content

Commit

Permalink
condition: Reject <, <=, >=, > with optional scalar against empty set.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: 09e2560 ("ovsdb: Allow comparison on optional scalar types")
Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Justin Pettit <[email protected]>
  • Loading branch information
blp committed Oct 4, 2018
1 parent fcaba95 commit 64107d5
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 4 deletions.
7 changes: 4 additions & 3 deletions Documentation/ref/ovsdb-server.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ovsdb/condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
256 changes: 255 additions & 1 deletion tests/ovsdb-condition.at
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 64107d5

Please sign in to comment.