Skip to content

Commit

Permalink
Fix host validation in parse_url.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: abce3f846d5d47949478da8353b2eb469635c404
  • Loading branch information
levlam committed Jun 30, 2018
1 parent 07f731d commit 9e6ddb1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tdutils/td/utils/HttpUrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ Result<HttpUrl> parse_url(MutableSlice url, HttpUrl::Protocol default_protocol)
string host_str = to_lower(host);
for (size_t i = 0; i < host_str.size(); i++) {
char c = host_str[i];
if (is_ipv6) {
if (c == ':' || ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || c == '.') {
continue;
}
return Status::Error("Wrong IPv6 URL host");
}

if (('a' <= c && c <= 'z') || c == '.' || ('0' <= c && c <= '9') || c == '-' || c == '_' || c == '!' || c == '$' ||
c == ',' || c == '~' || c == '*' || c == '\'' || c == '(' || c == ')' || c == ';' || c == '&' || c == '+' ||
c == '=') {
Expand All @@ -145,7 +152,9 @@ Result<HttpUrl> parse_url(MutableSlice url, HttpUrl::Protocol default_protocol)
continue;
}
}
return Status::Error("Wrong percent-encoded symbol in URL host");
}

// all other symbols aren't allowed
unsigned char uc = static_cast<unsigned char>(c);
if (uc >= 128) {
Expand Down

0 comments on commit 9e6ddb1

Please sign in to comment.