Var: Fix null-pointer deref on redefinition of lambdas

Closes #3314
This commit is contained in:
Arne Welzel 2023-09-27 11:08:35 +02:00
parent e22bf8ebb6
commit 8ede22f6ec
11 changed files with 76 additions and 10 deletions

View file

@ -26,8 +26,7 @@
namespace zeek::detail
{
static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs,
const ExprPtr& init)
static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs)
{
if ( ! IsFunc(id->GetType()->Tag()) )
return false;
@ -53,12 +52,6 @@ static bool add_prototype(const IDPtr& id, Type* t, std::vector<AttrPtr>* attrs,
return false;
}
if ( init )
{
init->Error("initialization not allowed during event/hook alternate prototype declaration");
return false;
}
const auto& canon_args = canon_ft->Params();
const auto& alt_args = alt_ft->Params();
@ -221,8 +214,8 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
else if ( dt != VAR_REDEF || init || ! attr )
{
if ( IsFunc(id->GetType()->Tag()) )
add_prototype(id, t.get(), attr.get(), init);
if ( IsFunc(id->GetType()->Tag()) && ! init )
add_prototype(id, t.get(), attr.get());
else
id->Error("already defined", init.get());

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 3: already defined (f)

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 2: redeclaration of function (function() : void and function() : void)

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 4 and <...>/redeclaration-redefinition-errors.zeek, line 5: already defined (f)

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 4 and <...>/redeclaration-redefinition-errors.zeek, line 3: redeclaration of function (function() : void and function() : void)

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 4: already defined (x)

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: alternate function prototype already exists (event() and record { })

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (hook() : bool and event())
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (function() : void and event())

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 2 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (hook() : bool and function() : void)
error in <...>/redeclaration-redefinition-errors.zeek, line 3 and <...>/redeclaration-redefinition-errors.zeek, line 1: incompatible function flavor (event() and function() : void)

View file

@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/redeclaration-redefinition-errors.zeek, line 6 and <...>/redeclaration-redefinition-errors.zeek, line 7: already defined (x)

View file

@ -0,0 +1,53 @@
# @TEST-DOC: Test some redeclaration, redefinition errors.
# @TEST-EXEC-FAIL: zeek -b %INPUT >out 2>&1
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
global x = 1;
global x = 2;
@TEST-START-NEXT
global f: function() = function() { };
global f: function() = function() { };
@TEST-START-NEXT
global f: function();
global f: function();
@TEST-START-NEXT
event zeek_init()
{
local f = function() { };
local f = function() { };
}
@TEST-START-NEXT
event zeek_init()
{
local f: function();
local f: function();
}
@TEST-START-NEXT
event zeek_init()
{
local x = 1;
local x = 2;
}
@TEST-START-NEXT
global ev: event();
global ev: event();
@TEST-START-NEXT
global f: event();
global f: hook();
global f: function();
@TEST-START-NEXT
global f = function() { };
global f: hook();
global f: event();