Merge remote-tracking branch 'htonl/weird_segfault'

* htonl/weird_segfault:
  Add btest test case
  Fix typo
  Fix segfault with incomplete connection
This commit is contained in:
Tim Wojtulewicz 2021-06-27 10:46:01 -07:00
commit c1b2989035
5 changed files with 38 additions and 1 deletions

10
CHANGES
View file

@ -1,3 +1,13 @@
4.1.0-dev.760 | 2021-06-27 10:46:01 -0700
* Add btest test case (Luke Cesarz)
* Fix typo (Luke Cesarz)
* Fix segfault with incomplete connection
Add required HasField check before GetFieldAs call (Luke Cesarz)
4.1.0-dev.755 | 2021-06-23 13:53:54 -0700 4.1.0-dev.755 | 2021-06-23 13:53:54 -0700
* Call brew update-reset in ci/macos/prepare.sh * Call brew update-reset in ci/macos/prepare.sh

View file

@ -1 +1 @@
4.1.0-dev.755 4.1.0-dev.760

View file

@ -380,6 +380,10 @@ bool Reporter::PermitFlowWeird(const char* name,
bool Reporter::PermitExpiredConnWeird(const char* name, const RecordVal& conn_id) bool Reporter::PermitExpiredConnWeird(const char* name, const RecordVal& conn_id)
{ {
if ( !conn_id.HasField("orig_h") || !conn_id.HasField("resp_h") ||
!conn_id.HasField("orig_p") || !conn_id.HasField("resp_p") )
return false;
auto conn_tuple = std::make_tuple(conn_id.GetFieldAs<AddrVal>("orig_h"), auto conn_tuple = std::make_tuple(conn_id.GetFieldAs<AddrVal>("orig_h"),
conn_id.GetFieldAs<AddrVal>("resp_h"), conn_id.GetFieldAs<AddrVal>("resp_h"),
conn_id.GetFieldAs<PortVal>("orig_p")->Port(), conn_id.GetFieldAs<PortVal>("orig_p")->Port(),

View file

@ -1202,6 +1202,18 @@ public:
return (*record_val)[field] ? true : false; return (*record_val)[field] ? true : false;
} }
/**
* Returns true if the given field is in the record, false if
* it's missing.
* @param field The field name to retrieve.
* @return Whether there's a value for the given field name.
*/
bool HasField(const char *field) const
{
int idx = GetType()->AsRecordType()->FieldOffset(field);
return HasField(idx);
}
/** /**
* Returns the value of a given field index. * Returns the value of a given field index.
* @param field The field index to retrieve. * @param field The field index to retrieve.

View file

@ -0,0 +1,11 @@
#
# @TEST-EXEC: zeek -b %INPUT
event zeek_init()
{
local x: connection;
x$uid = "uid";
Reporter::conn_weird("foo", x);
print "done";
}