mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-1155-recursive-table-index-type-check'
* origin/topic/jsiwek/gh-1155-recursive-table-index-type-check: GH-1155: Recursively check table index for unsupported types
This commit is contained in:
commit
26808ea7d4
7 changed files with 114 additions and 8 deletions
14
CHANGES
14
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
|
3.3.0-dev.265 | 2020-09-17 11:24:42 -0700
|
||||||
|
|
||||||
* Avoid passing address of member in packed struct #1074
|
* Avoid passing address of member in packed struct #1074
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
3.3.0-dev.265
|
3.3.0-dev.269
|
||||||
|
|
69
src/Type.cc
69
src/Type.cc
|
@ -441,6 +441,65 @@ bool IndexType::IsSubNetIndex() const
|
||||||
return false;
|
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)
|
TableType::TableType(TypeListPtr ind, TypePtr yield)
|
||||||
: IndexType(TYPE_TABLE, std::move(ind), std::move(yield))
|
: IndexType(TYPE_TABLE, std::move(ind), std::move(yield))
|
||||||
{
|
{
|
||||||
|
@ -448,6 +507,7 @@ TableType::TableType(TypeListPtr ind, TypePtr yield)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto& tl = indices->GetTypes();
|
const auto& tl = indices->GetTypes();
|
||||||
|
const char* unsupported_type_name = nullptr;
|
||||||
|
|
||||||
for ( const auto& tli : tl )
|
for ( const auto& tli : tl )
|
||||||
{
|
{
|
||||||
|
@ -456,12 +516,11 @@ TableType::TableType(TypeListPtr ind, TypePtr yield)
|
||||||
if ( t == TYPE_INTERNAL_ERROR )
|
if ( t == TYPE_INTERNAL_ERROR )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Allow functions, since they can be compared
|
if ( ! is_supported_index_type(tli, &unsupported_type_name) )
|
||||||
// for Func* pointer equality.
|
|
||||||
if ( t == TYPE_INTERNAL_OTHER && tli->Tag() != TYPE_FUNC &&
|
|
||||||
tli->Tag() != TYPE_RECORD && tli->Tag() != TYPE_PATTERN )
|
|
||||||
{
|
{
|
||||||
tli->Error("bad index type");
|
auto msg = util::fmt("index type containing '%s' is not supported",
|
||||||
|
unsupported_type_name);
|
||||||
|
Error(msg, tli.get());
|
||||||
SetError();
|
SetError();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,6 @@ F
|
||||||
[a] = [type_name=set[double], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[a] = [type_name=set[double], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[d] = [type_name=table[double,string] of table[string] of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[d] = [type_name=table[double,string] of table[string] of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[b] = [type_name=set[double,string], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[b] = [type_name=set[double,string], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[c] = [type_name=set[double,record r], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[c] = [type_name=set[double,record tt], log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[e] = [type_name=vector of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>]
|
[e] = [type_name=vector of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
|
@ -27,7 +27,7 @@ type mystring: string;
|
||||||
type cr: record {
|
type cr: record {
|
||||||
a: set[double];
|
a: set[double];
|
||||||
b: set[double, string];
|
b: set[double, string];
|
||||||
c: set[double, r];
|
c: set[double, tt];
|
||||||
d: table[double, string] of table[string] of vector of string;
|
d: table[double, string] of table[string] of vector of string;
|
||||||
e: vector of vector of string;
|
e: vector of vector of string;
|
||||||
};
|
};
|
||||||
|
|
26
testing/btest/language/table-index-unsupported-types.zeek
Normal file
26
testing/btest/language/table-index-unsupported-types.zeek
Normal file
|
@ -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];
|
Loading…
Add table
Add a link
Reference in a new issue