From bbbe32e443fe5e7399d3e81f77bc862fb5d3fed7 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Wed, 19 Jan 2011 11:12:41 -0800 Subject: [PATCH] Working around not being able to do lookup_addr() for IPv6 addresses. Rather than crashing, we warn the user once and then always time out the call. This addresses #291, and a #355 is new ticket scheduling fixing the actual problem to later. --- src/Trigger.cc | 6 ++++++ src/bro.bif | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Trigger.cc b/src/Trigger.cc index c9e236f1fa..e71c19732b 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -130,11 +130,17 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts, Val* timeout = arg_timeout ? arg_timeout->ExprVal() : 0; + // Make sure we don't get deleted if somebody calls a method like + // Timeout() while evaluating the trigger. + Ref(this); + if ( ! Eval() && timeout ) { timer = new TriggerTimer(timeout->AsInterval(), this); timer_mgr->Add(timer); } + + Unref(this); } Trigger::~Trigger() diff --git a/src/bro.bif b/src/bro.bif index af841600c8..bdcd898bcf 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -2813,7 +2813,7 @@ private: # function result. Therefore, they can only be called inside a when-condition. function lookup_addr%(host: addr%) : string %{ - // FIXME: Is should be easy to adapt the function to synchronous + // FIXME: It should be easy to adapt the function to synchronous // lookups if we're reading a trace. Trigger* trigger = frame->GetTrigger(); @@ -2829,8 +2829,18 @@ function lookup_addr%(host: addr%) : string #ifdef BROv6 if ( ! is_v4_addr(host) ) { - builtin_run_time("lookup_addr() only supports IPv4 addresses"); - return new StringVal(""); + // FIXME: This is a temporary work-around until we get this + // fixed. We warn the user once, and always trigger a timeout. + // Ticket #355 records the problem. + static bool warned = false; + if ( ! warned ) + { + warn("lookup_addr() only supports IPv4 addresses currently"); + warned = true; + } + + trigger->Timeout(); + return 0; } dns_mgr->AsyncLookupAddr(to_v4_addr(host),