mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Fix &default fields in records not being initialized in coerced assignments.
Addresses #722
This commit is contained in:
parent
f1e132cd1a
commit
f302f2f3f2
15 changed files with 52 additions and 23 deletions
|
@ -4053,7 +4053,14 @@ Val* RecordCoerceExpr::Fold(Val* v) const
|
||||||
val->Assign(i, rhs);
|
val->Assign(i, rhs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
val->Assign(i, 0);
|
{
|
||||||
|
const Attr* def =
|
||||||
|
Type()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT);
|
||||||
|
if ( def )
|
||||||
|
val->Assign(i, def->AttrExpr()->Eval(0));
|
||||||
|
else
|
||||||
|
val->Assign(i, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[a=42, b=<uninitialized>, c=<uninitialized>, d=Bar]
|
[a=42, b=Foo, c=<uninitialized>, d=Bar]
|
||||||
{
|
{
|
||||||
[b] = [type_name=record, log=F, value=<uninitialized>, default_val=Foo],
|
[b] = [type_name=record, log=F, value=Foo, default_val=Foo],
|
||||||
[d] = [type_name=record, log=T, value=Bar, default_val=<uninitialized>],
|
[d] = [type_name=record, log=T, value=Bar, default_val=<uninitialized>],
|
||||||
[c] = [type_name=record, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
[c] = [type_name=record, log=F, value=<uninitialized>, default_val=<uninitialized>],
|
||||||
[a] = [type_name=record, log=F, value=42, default_val=<uninitialized>]
|
[a] = [type_name=record, log=F, value=42, default_val=<uninitialized>]
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[a=13, c=13, v=[]]
|
||||||
|
0
|
||||||
|
[a=13, c=13, v=[test]]
|
||||||
|
1
|
|
@ -1,2 +1,2 @@
|
||||||
[t=1299718502.96511, id=[orig_h=1.2.3.4, orig_p=1234/tcp, resp_h=2.3.4.5, resp_p=80/tcp], status=success, country=<uninitialized>]
|
[t=1323970492.986366, id=[orig_h=1.2.3.4, orig_p=1234/tcp, resp_h=2.3.4.5, resp_p=80/tcp], status=success, country=unknown]
|
||||||
[t=1299718502.96511, id=[orig_h=1.2.3.4, orig_p=1234/tcp, resp_h=2.3.4.5, resp_p=80/tcp], status=failure, country=US]
|
[t=1323970492.986366, id=[orig_h=1.2.3.4, orig_p=1234/tcp, resp_h=2.3.4.5, resp_p=80/tcp], status=failure, country=US]
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
#path test.failure
|
#path test.failure
|
||||||
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
||||||
#types time addr port addr port string string
|
#types time addr port addr port string string
|
||||||
1315167053.923545 1.2.3.4 1234 2.3.4.5 80 failure US
|
1323970640.453742 1.2.3.4 1234 2.3.4.5 80 failure US
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
#path test.success
|
#path test.success
|
||||||
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
||||||
#types time addr port addr port string string
|
#types time addr port addr port string string
|
||||||
1315167053.923545 1.2.3.4 1234 2.3.4.5 80 success -
|
1323970640.453742 1.2.3.4 1234 2.3.4.5 80 success unknown
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
#path test.failure
|
#path test.failure
|
||||||
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
||||||
#types time addr port addr port string string
|
#types time addr port addr port string string
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 failure US
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 failure US
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 failure UK
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 failure UK
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 failure MX
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 failure MX
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#path test
|
#path test
|
||||||
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
||||||
#types time addr port addr port string string
|
#types time addr port addr port string string
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 success -
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 success unknown
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 failure US
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 failure US
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 failure UK
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 failure UK
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 success BR
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 success BR
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 failure MX
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 failure MX
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
#path test.success
|
#path test.success
|
||||||
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
#fields t id.orig_h id.orig_p id.resp_h id.resp_p status country
|
||||||
#types time addr port addr port string string
|
#types time addr port addr port string string
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 success -
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 success unknown
|
||||||
1315167059.502670 1.2.3.4 1234 2.3.4.5 80 success BR
|
1323970700.744867 1.2.3.4 1234 2.3.4.5 80 success BR
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
#path notice
|
#path notice
|
||||||
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
||||||
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
||||||
1316952194.679491 - - - - - Test_Notice Threshold crossed by metric_index(host=1.2.3.4) 100/100 - 1.2.3.4 - - 100 manager-1 Notice::ACTION_LOG 6 3600.000000 - - - - - - 1.2.3.4 - -
|
1323971217.669520 - - - - - Test_Notice Threshold crossed by metric_index(host=1.2.3.4) 100/100 - 1.2.3.4 - - 100 manager-1 Notice::ACTION_LOG 6 3600.000000 F - - - - - 1.2.3.4 - -
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
#path notice
|
#path notice
|
||||||
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
||||||
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
||||||
1316952223.891502 - - - - - Test_Notice Threshold crossed by metric_index(host=1.2.3.4) 3/2 - 1.2.3.4 - - 3 bro Notice::ACTION_LOG 6 3600.000000 - - - - - - 1.2.3.4 - -
|
1323971243.445213 - - - - - Test_Notice Threshold crossed by metric_index(host=1.2.3.4) 3/2 - 1.2.3.4 - - 3 bro Notice::ACTION_LOG 6 3600.000000 F - - - - - 1.2.3.4 - -
|
||||||
1316952223.891502 - - - - - Test_Notice Threshold crossed by metric_index(host=6.5.4.3) 2/2 - 6.5.4.3 - - 2 bro Notice::ACTION_LOG 6 3600.000000 - - - - - - 6.5.4.3 - -
|
1323971243.445213 - - - - - Test_Notice Threshold crossed by metric_index(host=6.5.4.3) 2/2 - 6.5.4.3 - - 2 bro Notice::ACTION_LOG 6 3600.000000 F - - - - - 6.5.4.3 - -
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
#path notice
|
#path notice
|
||||||
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
||||||
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
||||||
1316952264.931290 - - - - - Test_Notice test notice! - - - - - worker-1 Notice::ACTION_LOG 6 3600.000000 - - - - - - - - -
|
1323971344.565540 - - - - - Test_Notice test notice! - - - - - worker-1 Notice::ACTION_LOG 6 3600.000000 F - - - - - - - -
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
#path notice
|
#path notice
|
||||||
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude metric_index.host metric_index.str metric_index.network
|
||||||
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double addr string subnet
|
||||||
1316950574.408256 - - - - - Test_Notice test notice! - - - - - worker-2 Notice::ACTION_LOG 6 3600.000000 - - - - - - - - -
|
1323971387.261655 - - - - - Test_Notice test notice! - - - - - worker-2 Notice::ACTION_LOG 6 3600.000000 F - - - - - - - -
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
#path notice
|
#path notice
|
||||||
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude
|
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p note msg sub src dst p n peer_descr actions policy_items suppress_for dropped remote_location.country_code remote_location.region remote_location.city remote_location.latitude remote_location.longitude
|
||||||
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double
|
#types time string addr port addr port enum string string addr addr port count string table table interval bool string string string double double
|
||||||
1316950497.513136 - - - - - Test_Notice test - - - - - bro Notice::ACTION_LOG 6 3600.000000 - - - - - -
|
1323971422.944442 - - - - - Test_Notice test - - - - - bro Notice::ACTION_LOG 6 3600.000000 F - - - - -
|
||||||
|
|
18
testing/btest/language/record-default-coercion.bro
Normal file
18
testing/btest/language/record-default-coercion.bro
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# @TEST-EXEC: bro -b %INPUT >out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
type MyRecord: record {
|
||||||
|
a: count &default=13;
|
||||||
|
c: count;
|
||||||
|
v: vector of string &default=vector();
|
||||||
|
};
|
||||||
|
|
||||||
|
event bro_init()
|
||||||
|
{
|
||||||
|
local r: MyRecord = [$c=13];
|
||||||
|
print r;
|
||||||
|
print |r$v|;
|
||||||
|
r$v[|r$v|] = "test";
|
||||||
|
print r;
|
||||||
|
print |r$v|;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue