mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 16:18:19 +00:00
Fix using clear_table() within an &expire_func
This previously crashed since clear_table()/TableVal::RemoveAll() left behind a stale iterator to the old table causing a heap-use-after-free when resuming table expiry iteration in TableVal::DoExpire().
This commit is contained in:
parent
76483a9efa
commit
d51bd4bc46
3 changed files with 35 additions and 1 deletions
|
@ -1459,6 +1459,8 @@ TableVal::~TableVal()
|
|||
|
||||
void TableVal::RemoveAll()
|
||||
{
|
||||
delete expire_iterator;
|
||||
expire_iterator = nullptr;
|
||||
// Here we take the brute force approach.
|
||||
delete table_val;
|
||||
table_val = new PDict<TableEntryVal>;
|
||||
|
@ -2575,6 +2577,10 @@ void TableVal::DoExpire(double t)
|
|||
|
||||
if ( ! v )
|
||||
{ // user-provided function deleted it
|
||||
if ( ! expire_iterator )
|
||||
// Entire table got dropped (e.g. clear_table() / RemoveAll())
|
||||
break;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2613,7 +2619,7 @@ void TableVal::DoExpire(double t)
|
|||
if ( modified )
|
||||
Modified();
|
||||
|
||||
if ( (*expire_iterator) == table_val->end_robust() )
|
||||
if ( ! expire_iterator || (*expire_iterator) == table_val->end_robust() )
|
||||
{
|
||||
delete expire_iterator;
|
||||
expire_iterator = nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue