Merge remote-tracking branch 'origin/topic/jsiwek/gh-839-fix-optional-subrecord-table-indices'

* origin/topic/jsiwek/gh-839-fix-optional-subrecord-table-indices:
  GH-839: Fix use of &optional sub-records within table/set indices
This commit is contained in:
Tim Wojtulewicz 2021-06-01 09:39:30 -07:00
commit 7393e13d67
5 changed files with 61 additions and 1 deletions

View file

@ -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)

View file

@ -1 +1 @@
4.1.0-dev.666
4.1.0-dev.669

View file

@ -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();

View file

@ -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=<uninitialized>]
}
T
T
T
T
T
0, {
}
T
T
T
T
T

View file

@ -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;