diff --git a/libi2pd/HTTP.cpp b/libi2pd/HTTP.cpp index f5c0b213..43a110bc 100644 --- a/libi2pd/HTTP.cpp +++ b/libi2pd/HTTP.cpp @@ -133,6 +133,7 @@ namespace http } /* hostname[:port][/path] */ + if (pos_p >= url.length ()) return false; /* nothing left after schema or user part */ if (url.at(pos_p) == '[') // ipv6 { auto pos_b = url.find(']', pos_p); diff --git a/tests/test-http-url.cpp b/tests/test-http-url.cpp index a5021c43..061c83ce 100644 --- a/tests/test-http-url.cpp +++ b/tests/test-http-url.cpp @@ -125,6 +125,12 @@ int main() { assert(url->frag == "frag"); delete url; + /* nothing after the schema or the user part: must not throw */ + url = new URL; + assert(url->parse("http://") == false); + assert(url->parse("http://user@") == false); + delete url; + return 0; }