From c89be2a13bcca67add897f70cff1d481a873cc24 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 25 Aug 2022 12:38:16 +0200 Subject: [PATCH] bifs/to_port: Avoid ASAN errors when calling to_port("") Ran into this when using to_port(getenv(...)) for an undefined/empty environment variable. ASAN doesn't like that the slash variable ends up being access behind the string. --- src/zeek.bif | 2 +- testing/btest/Baseline/bifs.to_port/out | 3 +++ testing/btest/bifs/to_port.zeek | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) 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;