diff --git a/CHANGES b/CHANGES index 7f61f1017f..8d9c5aa49a 100644 --- a/CHANGES +++ b/CHANGES @@ -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 * Call brew update-reset in ci/macos/prepare.sh diff --git a/VERSION b/VERSION index 37f0699464..027a7c826c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0-dev.755 +4.1.0-dev.760 diff --git a/src/Reporter.cc b/src/Reporter.cc index 39d38dcee8..9dcebeb9bc 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -380,6 +380,10 @@ bool Reporter::PermitFlowWeird(const char* name, 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("orig_h"), conn_id.GetFieldAs("resp_h"), conn_id.GetFieldAs("orig_p")->Port(), diff --git a/src/Val.h b/src/Val.h index ef04bfa206..7694532871 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1202,6 +1202,18 @@ public: 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. * @param field The field index to retrieve. diff --git a/testing/btest/core/empty_conn_weird.zeek b/testing/btest/core/empty_conn_weird.zeek new file mode 100644 index 0000000000..eb94cf2c3f --- /dev/null +++ b/testing/btest/core/empty_conn_weird.zeek @@ -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"; +}