mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Fix segfault with incomplete connection
Add required HasField check before GetFieldAs call
This commit is contained in:
parent
2de38750fd
commit
d29a43fb79
2 changed files with 16 additions and 0 deletions
|
@ -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.HadField("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(),
|
||||||
|
|
12
src/Val.h
12
src/Val.h
|
@ -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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue