Add tests exercising dictionary iteration during modification.

These are some of the reproducers from #2017 and #2032 by Arne Welzel.
This commit is contained in:
Robin Sommer 2022-04-13 16:14:09 +02:00
parent 09b132728c
commit 445903f808
No known key found for this signature in database
GPG key ID: 6BEDA4DA6B8B23E3
4 changed files with 228 additions and 0 deletions

Binary file not shown.

View file

@ -0,0 +1,52 @@
# @TEST-EXEC: zeek %INPUT
# @TEST-DOC: Regression test #2017; no output check, just shouldn't crash
redef table_expire_interval = 0.1sec;
redef table_incremental_step = 100;
redef table_expire_delay = 0.5sec;
redef exit_only_after_terminate = T;
global tbl: table[string] of vector of count &default = vector() &create_expire=1sec;
const populates_per_second = 100;
const populates_num = 100;
global done = F;
event do_terminate() {
terminate();
}
event cleanup(idx: string) {
delete tbl[idx];
# terminate a bit after all elements will finally have been expired
if ( done && |tbl| == 0 )
schedule 1sec { do_terminate() };
}
event populate(round: count) {
local i = 0;
while (++i < populates_num) {
local val = rand(1000000);
local val_str = cat(val);
# print(fmt("round %s %s val=%s", round, i, val));
tbl[val_str] = vector(val);
# Schedule an explicit delete at most a second away.
local random_cleanup_delay = double_to_interval(rand(100) / 100.0);
schedule random_cleanup_delay { cleanup(val_str) };
}
if ( round <= 200 ) {
print(fmt("round %s size=%s", round, |tbl|));
schedule 1sec/populates_per_second { populate(++round) };
}
else
done = T;
}
event zeek_init() {
event populate(1);
}

View file

@ -0,0 +1,108 @@
# @TEST-EXEC: zcat <$TRACES/echo-connections.pcap.gz | zeek --load-seeds 1.seeds -Cr - %INPUT
# @TEST-EXEC: zcat <$TRACES/echo-connections.pcap.gz | zeek --load-seeds 2.seeds -Cr - %INPUT
# @TEST-DOC: Regression test #2032; no output check, just shouldn't crash
redef table_expire_delay = 0.1sec;
redef table_incremental_step = 10;
redef table_expire_interval = 0.01sec;
# redef exit_only_after_terminate = T;
type Key: record {
c: count;
s1: string;
s2: string;
a1: addr;
a2: addr;
};
global insert_many: event(n: count);
global insert_many_f: function(n: count);
function expire(t: table[Key] of Key, k: Key): interval {
print(fmt("Expiring %s sz=%s", k, |t|));
schedule 0.2sec { insert_many(2 * |t| + 8) };
#insert_many_f(2 * |t| + 8);
return 0sec;
}
global tbl: table[Key] of Key &create_expire=0.1sec &expire_func=expire;
function make_key(i: count): Key {
return Key(
$c=i,
$s1=cat(i),
$s2=cat(2 * i),
$a1=count_to_v4_addr(1000000 + i),
$a2=count_to_v4_addr(2000000 + i)
);
}
event insert_many(n: count) {
local i = n;
while (++i < n + 37) {
local k = make_key(i);
tbl[k] = k;
}
}
function insert_many_f(n: count) {
local i = n;
while (++i < n + 37) {
local k = make_key(i);
tbl[k] = k;
}
}
event zeek_init() {
local k = make_key(1);
tbl[k] = k;
}
@TEST-START-FILE 1.seeds
3569182667
3864322632
2737717875
4292737228
959594593
3440781012
1483058089
950202215
611472157
2218394723
3885890563
1396441520
1851988456
3540954895
2626085489
3793122452
3535210719
936980445
3834222442
2355333979
113403102
@TEST-END-FILE
@TEST-START-FILE 2.seeds
4013930712
1835775324
3393047106
3151534432
2727962940
3990820447
792628001
3844857817
2661636943
2621115293
2909873159
3909343487
1003041063
1365337823
2042927118
3623503659
394335333
302877509
348858887
14638654
4267481449
@TEST-END-FILE

View file

@ -0,0 +1,68 @@
# @TEST-EXEC: zcat <$TRACES/echo-connections.pcap.gz | zeek --load-seeds 1.seeds -Cr - %INPUT
# @TEST-EXEC: zcat <$TRACES/echo-connections.pcap.gz | zeek --load-seeds 2.seeds -Cr - %INPUT
# @TEST-DOC: Regression test #2032; no output check, just shouldn't crash
redef table_expire_delay = 0.0001sec;
redef table_incremental_step = 1;
redef table_expire_interval = 0.001sec;
function expire(t: table[conn_id] of string, k: conn_id): interval {
# print(fmt("Expiring %s sz=%s", k, |t|));
return 0sec;
}
global recent_conns: table[conn_id] of string &create_expire=0.05sec &expire_func=expire;
event new_connection(c: connection) {
# print(fmt("%s %s", c$id, network_time()));
recent_conns[c$id] = c$uid;
}
@TEST-START-FILE 1.seeds
3569182667
3864322632
2737717875
4292737228
959594593
3440781012
1483058089
950202215
611472157
2218394723
3885890563
1396441520
1851988456
3540954895
2626085489
3793122452
3535210719
936980445
3834222442
2355333979
113403102
@TEST-END-FILE
@TEST-START-FILE 2.seeds
4013930712
1835775324
3393047106
3151534432
2727962940
3990820447
792628001
3844857817
2661636943
2621115293
2909873159
3909343487
1003041063
1365337823
2042927118
3623503659
394335333
302877509
348858887
14638654
4267481449
@TEST-END-FILE