diff --git a/CHANGES b/CHANGES index c8b87d68c3..dabcb33d0c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4.1.0-dev.669 | 2021-06-01 09:39:30 -0700 + + * GH-839: Fix use of &optional sub-records within table/set indices (Jon Siwek, Corelight) + 4.1.0-dev.666 | 2021-05-26 10:51:51 -0700 * Ensure SessionAdapter members are initialized (Tim Wojtulewicz, Corelight) diff --git a/VERSION b/VERSION index b7a018b454..4c068bef23 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0-dev.666 +4.1.0-dev.669 diff --git a/src/CompHash.cc b/src/CompHash.cc index de5bb5fbc7..cd556017cc 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -509,6 +509,9 @@ int CompositeHash::SingleTypeKeySize(Type* bt, const Val* v, case TYPE_RECORD: { + if ( ! v ) + return (optional && ! calc_static_size) ? sz : 0; + const RecordVal* rv = v ? v->AsRecordVal() : nullptr; RecordType* rt = bt->AsRecordType(); int num_fields = rt->NumFields(); diff --git a/testing/btest/Baseline/language.table-optional-subrecord-index/out b/testing/btest/Baseline/language.table-optional-subrecord-index/out new file mode 100644 index 0000000000..86505abdf5 --- /dev/null +++ b/testing/btest/Baseline/language.table-optional-subrecord-index/out @@ -0,0 +1,18 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +2, { +[subrec=[str=hi]], +[subrec=] +} +T +T +T +T +T +0, { + +} +T +T +T +T +T diff --git a/testing/btest/language/table-optional-subrecord-index.zeek b/testing/btest/language/table-optional-subrecord-index.zeek new file mode 100644 index 0000000000..9731ca41f5 --- /dev/null +++ b/testing/btest/language/table-optional-subrecord-index.zeek @@ -0,0 +1,35 @@ +# @TEST-EXEC: zeek -b %INPUT >out +# @TEST-EXEC: btest-diff out +# @TEST-DOC: Check functionality of a table/set index consisting of optional sub-records. + +type SubRec: record { + str: string; +}; + +type Rec: record { + subrec: SubRec &optional; +}; + +global myset: set[Rec] = set(); + +local i = Rec(); +local j = Rec($subrec=SubRec($str="hi")); +add myset[i]; +add myset[j]; +print |myset|, myset; + +# All membership tests below are expected to evaluate to true. +print i in myset; +print j in myset; +print Rec() in myset; +print Rec($subrec=SubRec($str="hi")) in myset; +print Rec($subrec=SubRec($str="no")) !in myset; + +delete myset[i]; +delete myset[j]; +print |myset|, myset; +print i !in myset; +print j !in myset; +print Rec() !in myset; +print Rec($subrec=SubRec($str="hi")) !in myset; +print Rec($subrec=SubRec($str="no")) !in myset;