Skip to content

Commit

Permalink
Make sure substr is invoked with pos less than string length.
Browse files Browse the repository at this point in the history
Change-Id: Ia9600fcc267051ca29a0e78c03af9b581f82a463
related-bug: 1536112
(cherry picked from commit 2fbce4c)
(cherry picked from commit 3206d5e)
  • Loading branch information
haripk committed Feb 1, 2016
1 parent 6ac2868 commit beb5f97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/http/http_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class HttpSession::RequestHandler : public Task {
}

void NotFound(HttpSession *session, const HttpRequest *request) {
string url = request->UrlPath().substr(1);
static const char no_response[] =
"HTTP/1.1 404 Not Found\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
Expand Down
10 changes: 5 additions & 5 deletions src/vnsw/agent/oper/vn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ bool VnEntry::GetPrefix(const Ip6Address &ip, Ip6Address *prefix,
std::string VnEntry::GetProject() const {
// TODO: update to get the project name from project-vn link.
// Currently, this info doesnt come to the agent
std::size_t start_pos = name_.find(":") + 1;
std::size_t end_pos = name_.find(":", start_pos);
if (end_pos == std::string::npos)
std::string name(name_.c_str());
char *saveptr;
if (strtok_r(const_cast<char *>(name.c_str()), ":", &saveptr) == NULL)
return "";

return name_.substr(start_pos, end_pos - start_pos);
char *project = strtok_r(NULL, ":", &saveptr);
return (project == NULL) ? "" : std::string(project);
}

int VnEntry::GetVxLanId() const {
Expand Down
4 changes: 3 additions & 1 deletion src/vnsw/agent/services/metadata_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ MetadataProxy::HandleMetadataRequest(HttpSession *session, const HttpRequest *re
header_options.push_back(std::string("X-Instance-ID-Signature: " +
signature));

std::string uri = request->UrlPath().substr(1); // ignore the first "/"
std::string uri = request->UrlPath();
if (uri.size())
uri = uri.substr(1); // ignore the first "/"
const std::string &body = request->Body();
{
HttpConnection *conn = GetProxyConnection(session, conn_close);
Expand Down

0 comments on commit beb5f97

Please sign in to comment.