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.
This commit is contained in:
Arne Welzel 2022-08-25 12:38:16 +02:00
parent 686eb54f95
commit c89be2a13b
3 changed files with 7 additions and 1 deletions

View file

@ -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;

View file

@ -6,6 +6,9 @@
0/udp
0/icmp
0/unknown
0/unknown
123/unknown
123/unknown
256/tcp
256/udp
256/icmp

View file

@ -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;