mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-286'
Added note about different behaviour to NEWS. Closes #286. * origin/topic/jsiwek/gh-286: GH-286: Check for record type mismatch in ternary operator
This commit is contained in:
commit
e2172018ee
5 changed files with 41 additions and 12 deletions
|
@ -268,16 +268,21 @@ function expire_string_data(data: table[string, Type] of MetaDataTable, idx: any
|
|||
# Function to check for intelligence hits.
|
||||
function find(s: Seen): bool
|
||||
{
|
||||
local ds = have_full_data ? data_store : min_data_store;
|
||||
|
||||
if ( s?$host )
|
||||
{
|
||||
return ((s$host in ds$host_data) ||
|
||||
(|matching_subnets(addr_to_subnet(s$host), ds$subnet_data)| > 0));
|
||||
if ( have_full_data )
|
||||
return ((s$host in data_store$host_data) ||
|
||||
(|matching_subnets(addr_to_subnet(s$host), data_store$subnet_data)| > 0));
|
||||
else
|
||||
return ((s$host in min_data_store$host_data) ||
|
||||
(|matching_subnets(addr_to_subnet(s$host), min_data_store$subnet_data)| > 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
return ([to_lower(s$indicator), s$indicator_type] in ds$string_data);
|
||||
if ( have_full_data )
|
||||
return ([to_lower(s$indicator), s$indicator_type] in data_store$string_data);
|
||||
else
|
||||
return ([to_lower(s$indicator), s$indicator_type] in min_data_store$string_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -499,16 +504,17 @@ function insert(item: Item)
|
|||
# Function to check whether an item is present.
|
||||
function item_exists(item: Item): bool
|
||||
{
|
||||
local ds = have_full_data ? data_store : min_data_store;
|
||||
|
||||
switch ( item$indicator_type )
|
||||
{
|
||||
case ADDR:
|
||||
return to_addr(item$indicator) in ds$host_data;
|
||||
return have_full_data ? to_addr(item$indicator) in data_store$host_data :
|
||||
to_addr(item$indicator) in min_data_store$host_data;
|
||||
case SUBNET:
|
||||
return to_subnet(item$indicator) in ds$subnet_data;
|
||||
return have_full_data ? to_subnet(item$indicator) in data_store$subnet_data :
|
||||
to_subnet(item$indicator) in min_data_store$subnet_data;
|
||||
default:
|
||||
return [item$indicator, item$indicator_type] in ds$string_data;
|
||||
return have_full_data ? [item$indicator, item$indicator_type] in data_store$string_data :
|
||||
[item$indicator, item$indicator_type] in min_data_store$string_data;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2336,10 +2336,16 @@ CondExpr::CondExpr(Expr* arg_op1, Expr* arg_op2, Expr* arg_op3)
|
|||
else if ( bt2 != bt3 )
|
||||
ExprError("operands must be of the same type");
|
||||
|
||||
else
|
||||
{
|
||||
if ( IsRecord(bt2) && IsRecord(bt3) &&
|
||||
! same_type(op2->Type(), op3->Type()) )
|
||||
ExprError("operands must be of the same type");
|
||||
else
|
||||
SetType(op2->Type()->Ref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CondExpr::~CondExpr()
|
||||
{
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
error in /Users/jon/pro/zeek/zeek/testing/btest/.tmp/language.ternary-record-mismatch/ternary-record-mismatch.bro, lines 13-14: operands must be of the same type ((F) ? (coerce [$a=a string, $b=6] to MyRecord) : [$a=a different string, $b=7])
|
|
@ -6,6 +6,6 @@
|
|||
#open 2018-02-27-17-25-30
|
||||
#fields ts level message location
|
||||
#types time enum string string
|
||||
0.000000 Reporter::INFO Tried to remove non-existing item '192.168.1.1' (Intel::ADDR). /home/jgras/devel/bro/scripts/base/frameworks/intel/./main.bro, lines 547-548
|
||||
0.000000 Reporter::INFO Tried to remove non-existing item '192.168.1.1' (Intel::ADDR). /home/jgras/devel/bro/scripts/base/frameworks/intel/./main.bro, lines 553-554
|
||||
0.000000 Reporter::INFO received termination signal (empty)
|
||||
#close 2018-02-27-17-25-30
|
||||
|
|
16
testing/btest/language/ternary-record-mismatch.bro
Normal file
16
testing/btest/language/ternary-record-mismatch.bro
Normal file
|
@ -0,0 +1,16 @@
|
|||
# @TEST-EXEC-FAIL: bro -b %INPUT >out 2>&1
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER="$SCRIPTS/diff-remove-abspath" btest-diff out
|
||||
|
||||
type MyRecord: record {
|
||||
a: string;
|
||||
b: count;
|
||||
c: bool &default = T;
|
||||
};
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local rec: MyRecord = record($a = "a string", $b = 6);
|
||||
local rec2: MyRecord = (F) ? MyRecord($a = "a string", $b = 6) :
|
||||
record($a = "a different string", $b = 7);
|
||||
rec2$c = F;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue