Improve type checking of records, addresses BIT-1159.

This commit is contained in:
Jon Siwek 2014-03-20 13:54:26 -05:00
parent 0f3ed1a553
commit b1fd161274
13 changed files with 118 additions and 58 deletions

View file

@ -1,3 +1,3 @@
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 6: no type given (asdfasdf)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 7: uninitialized list value ($ports=asdfasdf)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 7: bad record initializer ([$ports=asdfasdf])
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-bad-ctor/record-bad-ctor.bro, line 7: bad record initializer ((coerce [$ports=asdfasdf] to record { ports:error; }))

View file

@ -0,0 +1,11 @@
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 9 and count: type clash for field "a" ((coerce [$a=0] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 9: bad record initializer ((coerce [$a=0] to error))
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 12 and count: type clash for field "a" ((coerce [$a=1] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 12: bad record initializer ((coerce (coerce [$a=1] to error) to error))
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 18 and count: type clash for field "a" ((coerce [$a=2] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 22 and count: type clash for field "a" ((coerce [$a=3] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 22: bad record initializer ((coerce [$a=3] to error))
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 27 and count: type clash for field "a" ((coerce [$a=1000] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 33 and count: type clash for field "a" ((coerce [$a=1001] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 40 and count: type clash for field "a" ((coerce [$a=1002] to MyRec) and count)
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.record-type-checking/record-type-checking.bro, line 46 and count: type clash for field "a" ((coerce [$a=1003] to MyRec) and count)

View file

@ -1,6 +1,8 @@
# @TEST-EXEC: bro -b frameworks/software/vulnerable %INPUT >out
# @TEST-EXEC: bro -b %INPUT >out
# @TEST-EXEC: btest-diff out
@load frameworks/software/vulnerable
type MyRec: record {
min: count &optional;
max: count;

View file

@ -9,7 +9,7 @@ type Foo: record {
redef record Foo += {
c: count &default=42;
d: count &optional;
d: string &optional;
anotherset: set[count] &default=set();
};

View file

@ -0,0 +1,47 @@
# @TEST-EXEC-FAIL: bro -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
type MyRec: record {
a: port &default = 1/tcp;
};
# global, type deduction, named ctor
global grdn = MyRec($a = 0); # type clash in init
# global, type explicit, named ctor
global gren: MyRec = MyRec($a = 1); # type clash in init
# global, type deduction, anon ctor
global grda = [$a = 2]; # fine
event bro_init()
{
grda = MyRec($a = 2); # type clash in assignment
}
# global, type explicit, anon ctor
global grea: MyRec = [$a = 3]; # type clash
# local, type deduction, named ctor
event bro_init()
{
local lrdn = MyRec($a = 1000); # type clash
}
# local, type explicit, named ctor
event bro_init()
{
local lren: MyRec = MyRec($a = 1001); # type clash
}
# local, type deduction, anon ctor
event bro_init()
{
local lrda = [$a = 1002]; # fine
lrda = MyRec($a = 1002); # type clash
}
# local, type explicit, anon ctor
event bro_init()
{
local lrea: MyRec = [$a = 1003]; # type clash
}

View file

@ -28,7 +28,7 @@ global f: file = open_log_file("sizeof_demo");
global i: int = -10;
global iv: interval = -5sec;
global p: port = 80/tcp;
global r: example_record [ $i = 10 ];
global r: example_record = [ $i = +10 ];
global si: set[int];
global s: string = "Hello";
global sn: subnet = 192.168.0.0/24;

View file

@ -4,8 +4,8 @@
# This is loaded by default.
#@load base/utils/conn-ids
global c: conn_id = [ $orig_h = 10.0.0.100, $orig_p = 10000,
$resp_h = 10.0.0.200, $resp_p = 20000 ];
global c: conn_id = [ $orig_h = 10.0.0.100, $orig_p = 10000/tcp,
$resp_h = 10.0.0.200, $resp_p = 20000/tcp ];
print id_string(c);
print reverse_id_string(c);

View file

@ -11,20 +11,20 @@ global local_ip = 10.0.0.100;
global remote_ip = 192.168.1.100;
global local2local: conn_id = [
$orig_h = 10.0.0.100, $orig_p = 10000,
$resp_h = 10.0.0.200, $resp_p = 20000 ];
$orig_h = 10.0.0.100, $orig_p = 10000/tcp,
$resp_h = 10.0.0.200, $resp_p = 20000/tcp ];
global local2remote: conn_id = [
$orig_h = 10.0.0.100, $orig_p = 10000,
$resp_h = 192.168.1.100, $resp_p = 20000 ];
$orig_h = 10.0.0.100, $orig_p = 10000/tcp,
$resp_h = 192.168.1.100, $resp_p = 20000/tcp ];
global remote2local: conn_id = [
$orig_h = 192.168.1.100, $orig_p = 10000,
$resp_h = 10.0.0.100, $resp_p = 20000 ];
$orig_h = 192.168.1.100, $orig_p = 10000/tcp,
$resp_h = 10.0.0.100, $resp_p = 20000/tcp ];
global remote2remote: conn_id = [
$orig_h = 192.168.1.100, $orig_p = 10000,
$resp_h = 192.168.1.200, $resp_p = 20000 ];
$orig_h = 192.168.1.100, $orig_p = 10000/tcp,
$resp_h = 192.168.1.200, $resp_p = 20000/tcp ];
function test_host(ip: addr, h: Host, expect: bool)
{