From 4a09c128822570b08bb19b306a5f7662718e36cd Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 18 Dec 2012 15:08:18 -0600 Subject: [PATCH 1/2] Fix to_port() BIF for port strings with a port number of zero. --- src/bro.bif | 3 ++- testing/btest/Baseline/bifs.to_port/out | 3 +++ testing/btest/bifs/to_port.bro | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bro.bif b/src/bro.bif index d945e54ef4..bebcde18c3 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -2684,8 +2684,9 @@ function to_port%(s: string%): port if ( s->Len() < 10 ) { char* slash; + errno = 0; port = strtol(s->CheckString(), &slash, 10); - if ( port ) + if ( ! errno ) { ++slash; if ( streq(slash, "tcp") ) diff --git a/testing/btest/Baseline/bifs.to_port/out b/testing/btest/Baseline/bifs.to_port/out index 79796d605e..7744914c30 100644 --- a/testing/btest/Baseline/bifs.to_port/out +++ b/testing/btest/Baseline/bifs.to_port/out @@ -1,6 +1,9 @@ 123/tcp 123/udp 123/icmp +0/tcp +0/udp +0/icmp 0/unknown 256/tcp 256/udp diff --git a/testing/btest/bifs/to_port.bro b/testing/btest/bifs/to_port.bro index 0dfecac43e..b2289b8a21 100644 --- a/testing/btest/bifs/to_port.bro +++ b/testing/btest/bifs/to_port.bro @@ -7,6 +7,9 @@ event bro_init() print to_port("123/tcp"); print to_port("123/udp"); print to_port("123/icmp"); + print to_port("0/tcp"); + print to_port("0/udp"); + print to_port("0/icmp"); print to_port("not a port"); local a: transport_proto = tcp; From 98663fd534837f59806401f01499cd0d82bca22c Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 18 Dec 2012 15:31:50 -0600 Subject: [PATCH 2/2] Fix return value of hook calls that have no handlers. For this case, the return value is always true. --- src/Func.cc | 2 +- testing/btest/Baseline/language.hook/out | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Func.cc b/src/Func.cc index cf548b2d95..37ab7deee7 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -288,7 +288,7 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const assert(Flavor() == FUNC_FLAVOR_EVENT || Flavor() == FUNC_FLAVOR_HOOK); loop_over_list(*args, i) Unref((*args)[i]); - return 0 ; + return Flavor() == FUNC_FLAVOR_HOOK ? new Val(true, TYPE_BOOL) : 0; } SegmentProfiler(segment_logger, location); diff --git a/testing/btest/Baseline/language.hook/out b/testing/btest/Baseline/language.hook/out index bef25193b8..d4f367f875 100644 --- a/testing/btest/Baseline/language.hook/out +++ b/testing/btest/Baseline/language.hook/out @@ -3,6 +3,7 @@ myhook return F myhook return T myhook, &priority=5, [a=37, b=goobye world] F +T myhook3, 8 T myhook4, 2