mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 18:48:20 +00:00
Fix uninitialized locals in event/hook handlers from having a value.
Since values for local variables are referenced by offset within a Frame (not by identifier name), and event/hook handler bodies share a common Frame, the value offsets for local variables in different handlers may overlap. This meant locals in a handler without an initialization may actually end up referring to the value of a previous handler's local that has the same Frame offset. When executing the body, that can possibly result in a type-conflict error or give give unexpected results instead of a "use of uninitialized value" error. This patch makes it so uninitialized locals do always refer to a null value before executing the body of a event/hook handler, so that using them without assigning a value within the body will connsistently give a "use of uninitialized value" error. Addresses #932.
This commit is contained in:
parent
564e27abb6
commit
0a69b87f03
4 changed files with 38 additions and 8 deletions
16
src/Stmt.cc
16
src/Stmt.cc
|
@ -1789,13 +1789,21 @@ Val* InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
|
|||
ID* aggr = (*inits)[i];
|
||||
BroType* t = aggr->Type();
|
||||
|
||||
Val* v;
|
||||
if ( t->Tag() == TYPE_RECORD )
|
||||
Val* v = 0;
|
||||
|
||||
switch ( t->Tag() ) {
|
||||
case TYPE_RECORD:
|
||||
v = new RecordVal(t->AsRecordType());
|
||||
else if ( aggr->Type()->Tag() == TYPE_VECTOR )
|
||||
break;
|
||||
case TYPE_VECTOR:
|
||||
v = new VectorVal(t->AsVectorType());
|
||||
else
|
||||
break;
|
||||
case TYPE_TABLE:
|
||||
v = new TableVal(t->AsTableType(), aggr->Attrs());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
f->SetElement(aggr->Offset(), v);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue