Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out-of-bound access in URI #304

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/URI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ bool URIPath::Parse(const std::string &_str)
// explicitly check for it
this->dataPtr->isAbsolute = this->dataPtr->IsStringAbsolute(_str);
this->dataPtr->trailingSlash =
_str.back() == '/' && _str.size() != 1;
_str.size() > 1 &&_str.back() == '/';

return true;
}
Expand Down Expand Up @@ -1199,14 +1199,16 @@ bool URI::Parse(const std::string &_str)
size_t authEndPos = str.find_first_of("/?#",
authDelimPos + std::strlen(kAuthDelim));

if (authEndPos != std::string::npos &&
(str[authEndPos-1] == ':' && str[authEndPos] == '/'))
{
// This could be a windows file path of the form file://D:/path/to/file
// In this case, the authority is not present.
if (str[authEndPos-1] == ':' && str[authEndPos] == '/')
{
str.erase(0, std::strlen(kAuthDelim));
authorityPresent = false;
}
else if (localScheme != "file" && authEndPos == authDelimPos+2)
else if (localScheme != "file" &&
authEndPos == authDelimPos + std::strlen(kAuthDelim))
{
ignerr << "A host is manadatory when using a scheme other than file\n";
return false;
Expand Down