diff --git a/CHANGES b/CHANGES index 6aa9671535..819ef99b93 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,17 @@ + +3.3.0-dev.269 | 2020-09-17 11:42:38 -0700 + + * GH-1155: Recursively check table index for unsupported types + + Previously, container types used within a table/set index were not + deeply checked to ensure all constituents could be part of an index. (Jon Siwek, Corelight) + + * GH-1159: Fix vector-of-interval multiplication/division arithmetic + + Those operations done between a vector-of-interval and a + vector-of-arithmetic-type previously threw a runtime expression error + due to an incorrect coercion being used internally. (Jon Siwek, Corelight) + 3.3.0-dev.265 | 2020-09-17 11:24:42 -0700 * Avoid passing address of member in packed struct #1074 diff --git a/VERSION b/VERSION index 32d3544253..357764346f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.3.0-dev.265 +3.3.0-dev.269 diff --git a/src/Type.cc b/src/Type.cc index f4330ede72..80dafc7396 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -441,6 +441,65 @@ bool IndexType::IsSubNetIndex() const return false; } +static bool is_supported_index_type(const TypePtr& t, const char** tname) + { + if ( t->InternalType() != TYPE_INTERNAL_OTHER ) + return true; + + auto tag = t->Tag(); + + switch ( tag ) { + // Allow functions, since they can be compared for Func* pointer equality. + case TYPE_FUNC: + return true; + + case TYPE_PATTERN: + return true; + + case TYPE_RECORD: + { + auto rt = t->AsRecordType(); + + for ( auto i = 0; i < rt->NumFields(); ++i ) + if ( ! is_supported_index_type(rt->GetFieldType(i), tname) ) + return false; + + return true; + } + + case TYPE_LIST: + { + for ( const auto& type : t->AsTypeList()->GetTypes() ) + if ( ! is_supported_index_type(type, tname) ) + return false; + + return true; + } + + case TYPE_TABLE: + { + auto tt = t->AsTableType(); + + if ( ! is_supported_index_type(tt->GetIndices(), tname) ) + return false; + + const auto& yt = tt->Yield(); + + if ( ! yt ) + return true; + + return is_supported_index_type(yt, tname); + } + + case TYPE_VECTOR: + return is_supported_index_type(t->AsVectorType()->Yield(), tname); + + default: + *tname = type_name(tag); + return false; + } + } + TableType::TableType(TypeListPtr ind, TypePtr yield) : IndexType(TYPE_TABLE, std::move(ind), std::move(yield)) { @@ -448,6 +507,7 @@ TableType::TableType(TypeListPtr ind, TypePtr yield) return; const auto& tl = indices->GetTypes(); + const char* unsupported_type_name = nullptr; for ( const auto& tli : tl ) { @@ -456,12 +516,11 @@ TableType::TableType(TypeListPtr ind, TypePtr yield) if ( t == TYPE_INTERNAL_ERROR ) break; - // Allow functions, since they can be compared - // for Func* pointer equality. - if ( t == TYPE_INTERNAL_OTHER && tli->Tag() != TYPE_FUNC && - tli->Tag() != TYPE_RECORD && tli->Tag() != TYPE_PATTERN ) + if ( ! is_supported_index_type(tli, &unsupported_type_name) ) { - tli->Error("bad index type"); + auto msg = util::fmt("index type containing '%s' is not supported", + unsupported_type_name); + Error(msg, tli.get()); SetError(); break; } diff --git a/testing/btest/Baseline/bifs.records_fields/out b/testing/btest/Baseline/bifs.records_fields/out index 4ca9a9d573..45cc2abd41 100644 --- a/testing/btest/Baseline/bifs.records_fields/out +++ b/testing/btest/Baseline/bifs.records_fields/out @@ -52,6 +52,6 @@ F [a] = [type_name=set[double], log=F, value=, default_val=], [d] = [type_name=table[double,string] of table[string] of vector of string, log=F, value=, default_val=], [b] = [type_name=set[double,string], log=F, value=, default_val=], -[c] = [type_name=set[double,record r], log=F, value=, default_val=], +[c] = [type_name=set[double,record tt], log=F, value=, default_val=], [e] = [type_name=vector of vector of string, log=F, value=, default_val=] } diff --git a/testing/btest/Baseline/language.table-index-unsupported-types/out b/testing/btest/Baseline/language.table-index-unsupported-types/out new file mode 100644 index 0000000000..41d0e789db --- /dev/null +++ b/testing/btest/Baseline/language.table-index-unsupported-types/out @@ -0,0 +1,7 @@ +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 20 and any: index type containing 'any' is not supported (set[any] and any) +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 21 and any: index type containing 'any' is not supported (table[any] of count and any) +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 22 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, lines 4-5: index type containing 'any' is not supported (set[r] and r) +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 23 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, lines 4-5: index type containing 'any' is not supported (table[r] of count and r) +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 24 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, lines 8-9: index type containing 'any' is not supported (set[rr] and rr) +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 25 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, lines 12-13: index type containing 'any' is not supported (set[rv] and rv) +error in /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, line 26 and /home/jon/pro/zeek/zeek/testing/btest/.tmp/language.table-index-unsupported-types/table-index-unsupported-types.zeek, lines 16-17: index type containing 'any' is not supported (set[rt] and rt) diff --git a/testing/btest/bifs/records_fields.zeek b/testing/btest/bifs/records_fields.zeek index d8b8f488bc..7a0ab6e6fa 100644 --- a/testing/btest/bifs/records_fields.zeek +++ b/testing/btest/bifs/records_fields.zeek @@ -27,7 +27,7 @@ type mystring: string; type cr: record { a: set[double]; b: set[double, string]; - c: set[double, r]; + c: set[double, tt]; d: table[double, string] of table[string] of vector of string; e: vector of vector of string; }; diff --git a/testing/btest/language/table-index-unsupported-types.zeek b/testing/btest/language/table-index-unsupported-types.zeek new file mode 100644 index 0000000000..9cc2575316 --- /dev/null +++ b/testing/btest/language/table-index-unsupported-types.zeek @@ -0,0 +1,26 @@ +# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1 +# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out + +type r: record { + f: any; +}; + +type rr: record { + f: r; +}; + +type rv: record { + f: vector of any; +}; + +type rt: record { + f: table[count] of any; +}; + +global a: set[any]; +global b: table[any] of count; +global c: set[r]; +global d: table[r] of count; +global e: set[rr]; +global f: set[rv]; +global g: set[rt];