diff --git a/src/zeek.bif b/src/zeek.bif index a69764cf7e..4f991ef37e 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -2877,7 +2877,7 @@ function raw_bytes_to_v6_addr%(x: string%): addr function to_port%(s: string%): port %{ int port = 0; - if ( s->Len() < 10 ) + if ( s->Len() > 0 && s->Len() < 10 ) { char* slash; errno = 0; diff --git a/testing/btest/Baseline/bifs.to_port/out b/testing/btest/Baseline/bifs.to_port/out index ab28024817..dd88826ec0 100644 --- a/testing/btest/Baseline/bifs.to_port/out +++ b/testing/btest/Baseline/bifs.to_port/out @@ -6,6 +6,9 @@ 0/udp 0/icmp 0/unknown +0/unknown +123/unknown +123/unknown 256/tcp 256/udp 256/icmp diff --git a/testing/btest/bifs/to_port.zeek b/testing/btest/bifs/to_port.zeek index b1e220f982..8588dc229e 100644 --- a/testing/btest/bifs/to_port.zeek +++ b/testing/btest/bifs/to_port.zeek @@ -11,6 +11,9 @@ event zeek_init() print to_port("0/udp"); print to_port("0/icmp"); print to_port("not a port"); + print to_port(""); + print to_port("123"); + print to_port("123/"); local a: transport_proto = tcp; local b: transport_proto = udp;