Skip to content

Commit

Permalink
Added a few missing strdups to avoid crashes on calling free()
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed May 15, 2023
1 parent f5eba4f commit ea687e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lib/cache/subCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,10 +990,18 @@ bool subCacheItemInsert
//
cSubP->url = strdup(httpInfo.url.c_str());
urlParse(cSubP->url, &cSubP->protocolString, &cSubP->ip, &cSubP->port, &cSubP->rest);
cSubP->protocol = protocolFromString(cSubP->protocolString);
cSubP->ip = strdup(cSubP->ip);
cSubP->protocolString = strdup(cSubP->protocolString);
cSubP->rest = strdup(cSubP->rest);

if (cSubP->protocolString != NULL)
{
cSubP->protocol = protocolFromString(cSubP->protocolString);
cSubP->protocolString = strdup(cSubP->protocolString);
}

if (cSubP->ip != NULL)
cSubP->ip = strdup(cSubP->ip);

if (cSubP->rest != NULL)
cSubP->rest = strdup(cSubP->rest);

//
// String filters
Expand Down
3 changes: 3 additions & 0 deletions src/lib/mongoBackend/mongoSubCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ int mongoSubCacheItemInsert(const char* tenant, const BSONObj& sub)
cSubP->url = strdup(cSubP->httpInfo.url.c_str());
urlParse(cSubP->url, &cSubP->protocolString, &cSubP->ip, &cSubP->port, &cSubP->rest);
cSubP->protocol = protocolFromString(cSubP->protocolString);
cSubP->protocolString = strdup(cSubP->protocolString);
cSubP->rest = strdup(cSubP->rest);
cSubP->ip = strdup(cSubP->ip);

// q
cSubP->qText = sub.hasField("ldQ")? strdup(getStringFieldF(&sub, "ldQ")) : NULL;
Expand Down

0 comments on commit ea687e1

Please sign in to comment.