BIT-1785: fix scripts able to access uninitialized variables.

This commit is contained in:
Jon Siwek 2017-02-06 23:30:54 -06:00
parent 3cfe8cd294
commit c857f5c4dd
5 changed files with 38 additions and 0 deletions

View file

@ -33,6 +33,15 @@ Frame::~Frame()
Release(); Release();
} }
void Frame::Reset(int startIdx)
{
for ( int i = startIdx; i < size; ++i )
{
Unref(frame[i]);
frame[i] = 0;
}
}
void Frame::Release() void Frame::Release()
{ {
for ( int i = 0; i < size; ++i ) for ( int i = 0; i < size; ++i )

View file

@ -24,6 +24,7 @@ public:
frame[n] = v; frame[n] = v;
} }
void Reset(int startIdx);
void Release(); void Release();
void Describe(ODesc* d) const; void Describe(ODesc* d) const;

View file

@ -397,6 +397,7 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
bodies[i].stmts->GetLocationInfo()); bodies[i].stmts->GetLocationInfo());
Unref(result); Unref(result);
f->Reset(args->length());
try try
{ {

View file

@ -0,0 +1,2 @@
error in /home/jon/projects/bro/bro/testing/btest/.tmp/language.uninitialized-local2/uninitialized-local2.bro, line 19: value used but not set (var_b)
var_a is, baz

View file

@ -0,0 +1,25 @@
# @TEST-EXEC: bro -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
event test()
{
local var_a: string = "foo";
}
event test()
{
if ( F )
{
local var_b: string = "bar";
}
local var_a: string = "baz";
print "var_a is", var_a;
print "var_b is", var_b;
}
event bro_init()
{
event test();
}