diff --git a/scripts/base/frameworks/intel/main.bro b/scripts/base/frameworks/intel/main.bro index ffa115e92c..1f4f7afe23 100644 --- a/scripts/base/frameworks/intel/main.bro +++ b/scripts/base/frameworks/intel/main.bro @@ -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; } } diff --git a/src/Expr.cc b/src/Expr.cc index b51516d66b..737a9455ca 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2337,7 +2337,13 @@ CondExpr::CondExpr(Expr* arg_op1, Expr* arg_op2, Expr* arg_op3) ExprError("operands must be of the same type"); 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()); + } } } diff --git a/testing/btest/Baseline/language.ternary-record-mismatch/out b/testing/btest/Baseline/language.ternary-record-mismatch/out new file mode 100644 index 0000000000..0c1cefce0d --- /dev/null +++ b/testing/btest/Baseline/language.ternary-record-mismatch/out @@ -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]) diff --git a/testing/btest/Baseline/scripts.base.frameworks.intel.remove-non-existing/output b/testing/btest/Baseline/scripts.base.frameworks.intel.remove-non-existing/output index 03dcf582e9..fd0420cc79 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.intel.remove-non-existing/output +++ b/testing/btest/Baseline/scripts.base.frameworks.intel.remove-non-existing/output @@ -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 diff --git a/testing/btest/language/ternary-record-mismatch.bro b/testing/btest/language/ternary-record-mismatch.bro new file mode 100644 index 0000000000..068952a69f --- /dev/null +++ b/testing/btest/language/ternary-record-mismatch.bro @@ -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; + }