mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +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
2
testing/btest/Baseline/language.uninitialized-local/out
Normal file
2
testing/btest/Baseline/language.uninitialized-local/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
error in /Users/jsiwek/Projects/bro/bro/testing/btest/.tmp/language.uninitialized-local/uninitialized-local.bro, line 16: value used but not set (my_string)
|
||||
Continuing
|
23
testing/btest/language/uninitialized-local.bro
Normal file
23
testing/btest/language/uninitialized-local.bro
Normal file
|
@ -0,0 +1,23 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >out 2>&1
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
|
||||
|
||||
event testit() &priority=10
|
||||
{
|
||||
local my_count: count = 10;
|
||||
}
|
||||
|
||||
event testit()
|
||||
{
|
||||
# my_string's value occupies same Frame offset as my_count's from above
|
||||
# handler, but execution of this handler body should still "initialize"
|
||||
# it to a null value instead of referring to a left-over value of my_count.
|
||||
local my_string: string;
|
||||
local my_vector: vector of string;
|
||||
my_vector[0] = my_string;
|
||||
print "Continuing";
|
||||
}
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
event testit();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue