diff --git a/src/analyzer/protocol/dns/events.bif b/src/analyzer/protocol/dns/events.bif index 46d3822235..d271065642 100644 --- a/src/analyzer/protocol/dns/events.bif +++ b/src/analyzer/protocol/dns/events.bif @@ -498,7 +498,7 @@ event dns_unknown_reply%(c: connection, msg: dns_msg, ans: dns_answer%); ## ## .. note:: ## -## Note that this event will only be raised if ``dns_skip_all_addl`` +## Note that this event will only be raised if :zeek:see:`dns_skip_all_addl` ## is set to false. ## ## .. zeek:see:: dns_AAAA_reply dns_A_reply dns_CNAME_reply dns_HINFO_reply dns_MX_reply @@ -526,7 +526,7 @@ event dns_EDNS_addl%(c: connection, msg: dns_msg, ans: dns_edns_additional%); ## ## .. note:: ## -## Note that this event will only be raised if ``dns_skip_all_addl`` +## Note that this event will only be raised if :zeek:see:`dns_skip_all_addl` ## is set to false. ## ## .. zeek:see:: dns_AAAA_reply dns_A_reply dns_CNAME_reply dns_HINFO_reply dns_MX_reply @@ -556,7 +556,7 @@ event dns_EDNS_ecs%(c: connection, msg: dns_msg, opt: dns_edns_ecs%); ## ## .. note:: ## -## Note that this event will only be raised if ``dns_skip_all_addl`` +## Note that this event will only be raised if :zeek:see:`dns_skip_all_addl` ## is set to false. ## ## .. zeek:see:: dns_AAAA_reply dns_A_reply dns_CNAME_reply dns_HINFO_reply dns_MX_reply @@ -586,7 +586,7 @@ event dns_EDNS_tcp_keepalive%(c: connection, msg: dns_msg, opt: dns_edns_tcp_kee ## ## .. note:: ## -## Note that this event will only be raised if ``dns_skip_all_addl`` +## Note that this event will only be raised if :zeek:see:`dns_skip_all_addl` ## is set to false. ## ## .. zeek:see:: dns_AAAA_reply dns_A_reply dns_CNAME_reply dns_HINFO_reply dns_MX_reply @@ -614,7 +614,7 @@ event dns_EDNS_cookie%(c: connection, msg: dns_msg, opt: dns_edns_cookie%); ## ## .. note:: ## -## Note that ``ans`` will only be populated if ``dns_skip_all_addl`` +## Note that ``ans`` will only be populated if :zeek:see:`dns_skip_all_addl` ## is set to false. ## ## .. zeek:see:: dns_TSIG_addl @@ -633,10 +633,10 @@ event dns_TKEY%(c: connection, msg: dns_msg, ans: dns_tkey%); ## msg: The parsed DNS message header. ## ## ans: The parsed TSIG reply. -# +## ## .. note:: ## -## Note that this event will only be raised if ``dns_skip_all_addl`` +## Note that this event will only be raised if :zeek:see:`dns_skip_all_addl` ## is set to false. ## ## .. zeek:see:: dns_AAAA_reply dns_A_reply dns_CNAME_reply dns_EDNS_addl diff --git a/src/zeek.bif b/src/zeek.bif index 09b497e8c1..e15e7dbe39 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -5019,13 +5019,21 @@ function generate_all_events%(%) : bool ## This currently is mainly used to warn when events are defined that will not be used ## in certain conditions. ## +## Raises an error if the named event does not exist. +## ## event_name: event name to check ## ## returns: true if the named event is handled. function is_event_handled%(event_name: string%) : bool %{ auto *h = event_registry->Lookup(event_name->ToStdStringView()); - if ( h && *h ) + if ( ! h ) + { + zeek::emit_builtin_error(zeek::util::fmt("is_event_handled: '%s' is not an event", event_name->CheckString())); + return zeek::val_mgr->False(); + } + + if ( *h ) return zeek::val_mgr->True(); return zeek::val_mgr->False(); diff --git a/testing/btest/Baseline/bifs.is_event_handled/err b/testing/btest/Baseline/bifs.is_event_handled/err new file mode 100644 index 0000000000..b0c916b9a1 --- /dev/null +++ b/testing/btest/Baseline/bifs.is_event_handled/err @@ -0,0 +1,3 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +error in <...>/is_event_handled.zeek, line 11: is_event_handled: 'myfunc1' is not an event (is_event_handled(myfunc1)) +error in <...>/is_event_handled.zeek, line 12: is_event_handled: 'conn_id' is not an event (is_event_handled(conn_id)) diff --git a/testing/btest/Baseline/bifs.is_event_handled/out b/testing/btest/Baseline/bifs.is_event_handled/out new file mode 100644 index 0000000000..311b22d902 --- /dev/null +++ b/testing/btest/Baseline/bifs.is_event_handled/out @@ -0,0 +1,5 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +T +F +F +F diff --git a/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log b/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log index 353e066690..a7ed97effa 100644 --- a/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log +++ b/testing/btest/Baseline/coverage.default-load-baseline/canonified_loaded_scripts.log @@ -385,6 +385,7 @@ scripts/base/init-default.zeek scripts/base/protocols/dns/__load__.zeek scripts/base/protocols/dns/consts.zeek scripts/base/protocols/dns/main.zeek + scripts/base/protocols/dns/check-event-handlers.zeek scripts/base/protocols/finger/__load__.zeek scripts/base/protocols/finger/spicy-events.zeek scripts/base/protocols/finger/main.zeek diff --git a/testing/btest/bifs/is_event_handled.zeek b/testing/btest/bifs/is_event_handled.zeek new file mode 100644 index 0000000000..e3f8c1f6ed --- /dev/null +++ b/testing/btest/bifs/is_event_handled.zeek @@ -0,0 +1,12 @@ +# @TEST-EXEC: zeek -b %INPUT >out 2>err +# @TEST-EXEC: btest-diff out +# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff err + +function myfunc1(a: addr, b: addr): int + { + } + +print is_event_handled("zeek_init"); # T +print is_event_handled("dns_EDNS_cookie"); # F +print is_event_handled("myfunc1"); # builtin error +print is_event_handled("conn_id"); # builtin error