utils/decompose_uri: Support URIs containing IPv6 addresses

An URI containing a bracketed or non-bracketed IPv6 address of the form
http://[::1]:42 was previously split on the first colon for port extraction,
causing a subsequent to_count() call to fail. Harden this to check for a
digits in the last :[0-9]+ component.

Fixes #4842
This commit is contained in:
Arne Welzel 2025-09-23 10:12:45 +02:00
parent 416d997263
commit b3b0c3db7d
4 changed files with 52 additions and 8 deletions

View file

@ -1,5 +1,6 @@
# @TEST-EXEC: zeek -b %INPUT > output
# @TEST-EXEC: btest-diff output
# @TEST-EXEC: btest-diff .stderr
@load base/utils/urls
@ -29,5 +30,21 @@ event zeek_init()
dc("https://www.bro.org/documentation/faq.html?=v");
dc("file:///documentation/faq.html?=v");
dc("www.bro.org/?foo=bar");
# Bracketed IPv6
dc("http://[::1]:8080/?foo=bar&baz=qux");
dc("http://[::1]/foo/bar");
dc("http://[::1]/foo/bar");
dc("[::1]:80/test/a/b.exe?a=b");
# Un-bracketed is ambiguous, but not causing errors.
dc("http://beeb:deed::1/test");
dc("http://beeb:deed::1:8080/test");
# Ensure colons in path or query parameters do not
# cause trouble.
dc("https://en.wikipedia.org/wiki/Template:Welcome");
dc("https://[::1]:8080/wiki/Template:Welcome");
dc("https://[::1]:8080/wiki/Template:Welcome?key=:&value=:");
}