mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
GH-286: Check for record type mismatch in ternary operator
Fixes GH-286
This commit is contained in:
parent
a342090f18
commit
74c225c7cb
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 to check for intelligence hits.
|
||||||
function find(s: Seen): bool
|
function find(s: Seen): bool
|
||||||
{
|
{
|
||||||
local ds = have_full_data ? data_store : min_data_store;
|
|
||||||
|
|
||||||
if ( s?$host )
|
if ( s?$host )
|
||||||
{
|
{
|
||||||
return ((s$host in ds$host_data) ||
|
if ( have_full_data )
|
||||||
(|matching_subnets(addr_to_subnet(s$host), ds$subnet_data)| > 0));
|
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
|
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 to check whether an item is present.
|
||||||
function item_exists(item: Item): bool
|
function item_exists(item: Item): bool
|
||||||
{
|
{
|
||||||
local ds = have_full_data ? data_store : min_data_store;
|
|
||||||
|
|
||||||
switch ( item$indicator_type )
|
switch ( item$indicator_type )
|
||||||
{
|
{
|
||||||
case ADDR:
|
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:
|
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:
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2337,7 +2337,13 @@ CondExpr::CondExpr(Expr* arg_op1, Expr* arg_op2, Expr* arg_op3)
|
||||||
ExprError("operands must be of the same type");
|
ExprError("operands must be of the same type");
|
||||||
|
|
||||||
else
|
else
|
||||||
SetType(op2->Type()->Ref());
|
{
|
||||||
|
if ( IsRecord(bt2) && IsRecord(bt3) &&
|
||||||
|
! same_type(op2->Type(), op3->Type()) )
|
||||||
|
ExprError("operands must be of the same type");
|
||||||
|
else
|
||||||
|
SetType(op2->Type()->Ref());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
#open 2018-02-27-17-25-30
|
||||||
#fields ts level message location
|
#fields ts level message location
|
||||||
#types time enum string string
|
#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)
|
0.000000 Reporter::INFO received termination signal (empty)
|
||||||
#close 2018-02-27-17-25-30
|
#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