Skip to content

Commit

Permalink
Merge pull request #1273 from Barenboim/master
Browse files Browse the repository at this point in the history
Fix URIParser bug.
  • Loading branch information
Barenboim authored May 5, 2023
2 parents 1601c8b + a1b83ad commit baba965
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/util/URIParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ int URIParser::parse(const char *str, ParsedURI& uri)

int start_idx[URI_PART_ELEMENTS] = {0};
int end_idx[URI_PART_ELEMENTS] = {0};
int pre_state = URI_SCHEME;;
int i;
int pre_state = URI_SCHEME;
bool in_ipv6 = false;
int i;

for (i = 0; str[i]; i++)
{
Expand All @@ -268,7 +268,7 @@ int URIParser::parse(const char *str, ParsedURI& uri)
pre_state = URI_HOST;
i += 2;
if (str[i] == '[')
in_ipv6= true;
in_ipv6 = true;
else
start_idx[URI_USERINFO] = i;

Expand Down Expand Up @@ -341,6 +341,7 @@ int URIParser::parse(const char *str, ParsedURI& uri)
break;
}
}

if (pre_state != URI_PART_ELEMENTS)
end_idx[pre_state] = i;

Expand Down Expand Up @@ -369,6 +370,7 @@ int URIParser::parse(const char *str, ParsedURI& uri)
break;
}
}

end_idx[pre_state] = i + strlen(str + i);
}

Expand Down Expand Up @@ -398,13 +400,15 @@ int URIParser::parse(const char *str, ParsedURI& uri)
return -1;
}

if (i == URI_HOST && str[start_idx[i]] == '[')
if (i == URI_HOST && str[start_idx[i]] == '[' &&
str[end_idx[i] - 1] == ']')
{
len -= 2;
memcpy(*dst[i], str + start_idx[i] + 1, len);
}
else
memcpy(*dst[i], str + start_idx[i], len);

(*dst[i])[len] = '\0';
}
else
Expand Down

0 comments on commit baba965

Please sign in to comment.