zeek/testing/btest/bifs/lookup_connection.zeek
Arne Welzel 17836ef7d9 session/Manager: Emit explicit errors for FindConnection() with proto=65535
We silently broke users constructing conn_id records manually and
subsequently using them with lookup_connection() or connection_exists().

This is an attempt to at least report a runtime error about the situation
so it doesn't go completely unnoticed.
2025-01-17 17:57:49 +01:00

58 lines
1.4 KiB
Text

# @TEST-DOC: Test lookup_connection() and connection_exists()
#
# @TEST-EXEC: zeek -b -r $TRACES/http/get.trace %INPUT
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff .stderr
event new_connection(c: connection)
{
local c2 = lookup_connection(c$id);
assert c$uid == c2$uid;
local cid: conn_id;
cid$orig_h = c$id$orig_h;
cid$orig_p = c$id$orig_p;
cid$resp_h = c$id$resp_h;
cid$resp_p = c$id$resp_p;
# Produces an error on .stderr because cid$proto wasn't
# initialized and then returns a dummy record.
local c3 = lookup_connection(cid);
assert c3$history == "";
assert c3$id$orig_h == 0.0.0.0;
assert c3$id$orig_p == 0/udp;
cid$proto = c$id$proto;
local c4 = lookup_connection(cid);
assert c$uid == c4$uid;
}
event new_connection(c: connection)
{
# This needs to hold.
assert connection_exists(c$id);
local my_id: conn_id;
my_id$orig_h = c$id$orig_h;
my_id$orig_p = c$id$orig_p;
my_id$resp_h = c$id$resp_h;
my_id$resp_p = c$id$resp_p;
# Produces an error because cid$proto wasn't initialized.
assert ! connection_exists(my_id);
my_id$proto = c$id$proto;
assert connection_exists(my_id);
}
event new_connection(c: connection)
{
# This crashed previously!
local my_id: conn_id;
local c2 = lookup_connection(my_id);
assert c2$history == "";
assert c2$id$orig_h == 0.0.0.0;
assert c2$id$orig_p == 0/udp;
# This also crashed!
assert ! connection_exists(my_id);
}