From: Pieter Lexis Date: Wed, 12 Feb 2020 14:27:18 +0000 (+0100) Subject: YaHTTP: Parse addresses with IPv6 literals X-Git-Tag: auth-4.3.0-beta2~13^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efcfeb3301589ff25c585580d046d8199d5c1511;p=thirdparty%2Fpdns.git YaHTTP: Parse addresses with IPv6 literals A URL like http://[::1]:81 are parsed correctly now. --- diff --git a/ext/yahttp/yahttp/url.hpp b/ext/yahttp/yahttp/url.hpp index 0002c29339..fbdd48de86 100644 --- a/ext/yahttp/yahttp/url.hpp +++ b/ext/yahttp/yahttp/url.hpp @@ -38,7 +38,18 @@ namespace YaHTTP { host = url.substr(pos, pos1-pos); pos = pos1; } - if ( (pos1 = host.find_first_of(":")) != std::string::npos ) { + if (host.at(0) == '[') { // IPv6 + if ((pos1 = host.find_first_of("]")) == std::string::npos) { + // incomplete address + return false; + } + size_t pos2; + if ((pos2 = host.find_first_of(":", pos1)) != std::string::npos) { + std::istringstream tmp(host.substr(pos2 + 1)); + tmp >> port; + } + host = host.substr(1, pos1 - 1); + } else if ( (pos1 = host.find_first_of(":")) != std::string::npos ) { std::istringstream tmp(host.substr(pos1+1)); tmp >> port; host = host.substr(0, pos1);