From fef4fda2f761ab806b5ec16d974950d03f4b2e7c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Thu, 6 Aug 2020 20:48:08 -0700 Subject: [PATCH] Fix DNS script deleting a table element while iterating Doesn't typically cause any problems since the loop breaks after deleting, except there's now an assert in debug builds catching potential problems like this. --- scripts/base/protocols/dns/main.zeek | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/base/protocols/dns/main.zeek b/scripts/base/protocols/dns/main.zeek index 0a0da1aa82..98cc977a50 100644 --- a/scripts/base/protocols/dns/main.zeek +++ b/scripts/base/protocols/dns/main.zeek @@ -285,12 +285,19 @@ hook set_session(c: connection, msg: dns_msg, is_query: bool) &priority=5 else { # Just pick an arbitrary, unpaired query. + local tid: count; + local found_one = F; + for ( trans_id, q in c$dns_state$pending_queries ) if ( Queue::len(q) > 0 ) { - c$dns_state$pending_query = pop_msg(c$dns_state$pending_queries, trans_id); + tid = trans_id; + found_one = T; break; } + + if ( found_one ) + c$dns_state$pending_query = pop_msg(c$dns_state$pending_queries, tid); } } }