diff --git a/CHANGES b/CHANGES index 35e2064125..88c6869a6b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +4.2.0-dev.432 | 2021-12-10 09:28:23 -0700 + + * GH-1741: Print error if calling a non-hook with hook keyword (Tim Wojtulewicz, Corelight) + + * GH-1740: Report a better error message if table key is not a list (Tim Wojtulewicz, Corelight) + 4.2.0-dev.428 | 2021-12-09 14:58:53 -0700 * GH-1125: Support GRE ARUBA headers (Tim Wojtulewicz, Corelight) diff --git a/VERSION b/VERSION index 9c0a235d22..da18ae9734 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.0-dev.428 +4.2.0-dev.432 diff --git a/src/Expr.cc b/src/Expr.cc index b1d7ebb153..9271cf7e22 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2626,7 +2626,7 @@ TypePtr AssignExpr::InitType() const { if ( op1->Tag() != EXPR_LIST ) { - Error("bad initializer"); + Error("bad initializer, first operand should be a list"); return nullptr; } @@ -3490,7 +3490,10 @@ TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list, SetType(init_type(op.get())); if ( ! type ) + { SetError(); + return; + } else if ( type->Tag() != TYPE_TABLE || type->AsTableType()->IsSet() ) SetError("values in table(...) constructor do not specify a table"); diff --git a/src/parse.y b/src/parse.y index e7bf8fddac..cf60ff58ac 100644 --- a/src/parse.y +++ b/src/parse.y @@ -721,8 +721,12 @@ expr: { --in_hook; set_location(@1, @3); + if ( $3->Tag() != EXPR_CALL ) $3->Error("not a valid hook call expression"); + else if ( $3->AsCallExpr()->Func()->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_HOOK ) + $3->Error("hook keyword should only be used to call hooks"); + $$ = $3; } diff --git a/testing/btest/Baseline/language.hook_calls/invalid.out b/testing/btest/Baseline/language.hook_calls/invalid.out index 762168bcef..89ec4d01ac 100644 --- a/testing/btest/Baseline/language.hook_calls/invalid.out +++ b/testing/btest/Baseline/language.hook_calls/invalid.out @@ -1,9 +1,10 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -error in ./invalid.zeek, line 9: hook cannot be called directly, use hook operator (myhook) -error in ./invalid.zeek, line 10: hook cannot be called directly, use hook operator (myhook) -error in ./invalid.zeek, line 11: hook cannot be called directly, use hook operator (myhook) -error in ./invalid.zeek, line 12: not a valid hook call expression (2 + 2) -warning in ./invalid.zeek, line 12: expression value ignored (2 + 2) -error in ./invalid.zeek, line 13: not a valid hook call expression (2 + 2) -error in ./invalid.zeek, line 15: hook cannot be called directly, use hook operator (h) -error in ./invalid.zeek, line 16: hook cannot be called directly, use hook operator (h) +error in ./invalid.zeek, line 14: hook cannot be called directly, use hook operator (myhook) +error in ./invalid.zeek, line 15: hook cannot be called directly, use hook operator (myhook) +error in ./invalid.zeek, line 16: hook cannot be called directly, use hook operator (myhook) +error in ./invalid.zeek, line 17: not a valid hook call expression (2 + 2) +warning in ./invalid.zeek, line 17: expression value ignored (2 + 2) +error in ./invalid.zeek, line 18: not a valid hook call expression (2 + 2) +error in ./invalid.zeek, line 20: hook cannot be called directly, use hook operator (h) +error in ./invalid.zeek, line 21: hook cannot be called directly, use hook operator (h) +error in ./invalid.zeek, line 24: hook keyword should only be used to call hooks (foo()) diff --git a/testing/btest/language/hook_calls.zeek b/testing/btest/language/hook_calls.zeek index eee92f1e2a..89ba9bc4cc 100644 --- a/testing/btest/language/hook_calls.zeek +++ b/testing/btest/language/hook_calls.zeek @@ -15,7 +15,7 @@ hook myhook(i: count) hook myhook(i: count) &priority=-1 { print "other myhook()", i; - } + } function indirect(): hook(i: count) { @@ -66,6 +66,11 @@ hook myhook(i: count) if ( i == 0 ) break; } +function foo() + { + print "foo()"; + } + event zeek_init() { myhook(3); @@ -78,5 +83,6 @@ event zeek_init() if ( h(3) ) print "hmm"; print "done"; + hook foo(); } @TEST-END-FILE