Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/vern/dup-rec-fields2'
Browse files Browse the repository at this point in the history
* origin/topic/vern/dup-rec-fields2:
  fix for crashes when record definitions repeat a field name

Removed dead if !init code during merge.
  • Loading branch information
awelzel committed Jan 12, 2023
2 parents 144cadf + a172617 commit d4a84e7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
5.2.0-dev.478 | 2023-01-12 09:41:11 +0100

* fix for crashes when record definitions repeat a field name (Vern Paxson, Corelight)

5.2.0-dev.476 | 2023-01-11 17:00:32 -0800

* CI updates (Christian Kreibich, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.0-dev.476
5.2.0-dev.478
25 changes: 14 additions & 11 deletions src/Type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1062,22 +1062,25 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td)
ASSERT(field == field_inits.size());
ASSERT(field == managed_fields.size());

if ( field_ids.count(td->id) != 0 )
{
reporter->Error("Duplicate field '%s' found in record definition\n", td->id);
return;
}
else
{
field_ids.insert(std::string(td->id));
}

managed_fields.push_back(ZVal::IsManagedType(td->type));

auto init = new FieldInit();
init->init_type = FieldInit::R_INIT_NONE;

init->attrs = td->attrs;

// We defer error-checking until here so that we can keep field_inits
// and managed_fields correctly tracking the associated fields.

if ( field_ids.count(td->id) != 0 )
{
reporter->Error("duplicate field '%s' found in record definition", td->id);
field_inits.push_back(init);
return;
}

field_ids.insert(std::string(td->id));

auto a = init->attrs;

auto type = td->type;
Expand Down Expand Up @@ -1335,7 +1338,7 @@ void RecordType::Create(std::vector<std::optional<ZVal>>& r) const

for ( int i = 0; i < n; ++i )
{
auto& init = field_inits[i];
auto* init = field_inits[i];

ZVal r_i;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/record-duplicate-fields.zeek, line 7: Duplicate field 'a' found in record definition

error in <...>/record-duplicate-fields.zeek, line 7: duplicate field 'a' found in record definition
error in <...>/record-duplicate-fields.zeek, line 17: duplicate field 'a' found in record definition
error in <...>/record-duplicate-fields.zeek, line 23: duplicate field 'a' found in record definition
error in <...>/record-duplicate-fields.zeek, line 32: duplicate field 'a' found in record definition
error in <...>/record-duplicate-fields.zeek, line 32: duplicate field 'b' found in record definition
error in <...>/record-duplicate-fields.zeek, line 32: duplicate field 'a' found in record definition
31 changes: 31 additions & 0 deletions testing/btest/language/record-duplicate-fields.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,39 @@ type test: record {
a: string &optional;
};

type r1: record {
a: count;
b: count;
};

type r2: record {
a: count;
a: count;
};

type r3: record {
b: count;
a: count;
a: count;
};

type r4: record {
a: count;
b: count;
a: count;
b: count;
a: count;
c: count;
};

global x1: r1;
global x2: r2;
global x3: r3;
global x4: r4;

event zeek_init()
{
local a = test($a=5);
print a;
print x1, x2, x3, x4;
}

0 comments on commit d4a84e7

Please sign in to comment.