Skip to content

Commit 62d4a53

Browse files
committed
CEF reworks #5: Better safety and less memory waste/fix edge-case mem leaks
1 parent 7ff126e commit 62d4a53

File tree

2 files changed

+434
-44
lines changed

2 files changed

+434
-44
lines changed

Client/cefweb/CWebCore.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ void CWebCore::AddAllowedPage(const SString& strURL, eWebFilterType filterType)
586586
std::lock_guard<std::recursive_mutex> lock(m_FilterMutex);
587587

588588
// Prevent unbounded whitelist growth - remove old REQUEST entries if limit reached
589-
if (m_Whitelist.size() >= MAX_WHITELIST_SIZE)
589+
if (m_Whitelist.size() >= 50000)
590590
{
591591
// Remove WEBFILTER_REQUEST entries (temporary session entries)
592592
for (auto iter = m_Whitelist.begin(); iter != m_Whitelist.end();)
@@ -606,7 +606,7 @@ void CWebCore::AddBlockedPage(const SString& strURL, eWebFilterType filterType)
606606
std::lock_guard<std::recursive_mutex> lock(m_FilterMutex);
607607

608608
// Prevent unbounded whitelist growth - remove old REQUEST entries if limit reached
609-
if (m_Whitelist.size() >= MAX_WHITELIST_SIZE)
609+
if (m_Whitelist.size() >= 50000)
610610
{
611611
// Remove WEBFILTER_REQUEST entries (temporary session entries)
612612
for (auto iter = m_Whitelist.begin(); iter != m_Whitelist.end();)
@@ -1026,6 +1026,9 @@ void CWebCore::StaticFetchRevisionFinished(const SHttpDownloadResult& result)
10261026

10271027
if (result.bSuccess)
10281028
{
1029+
if (result.dataSize > 1024 * 1024) [[unlikely]]
1030+
return;
1031+
10291032
SString strData = result.pData;
10301033
SString strWhiteRevision, strBlackRevision;
10311034
strData.Split(";", &strWhiteRevision, &strBlackRevision);
@@ -1073,10 +1076,21 @@ void CWebCore::StaticFetchWhitelistFinished(const SHttpDownloadResult& result)
10731076
if (!pWebCore->MakeSureXMLNodesExist())
10741077
return;
10751078

1079+
if (result.dataSize > 5 * 1024 * 1024) [[unlikely]]
1080+
{
1081+
return;
1082+
}
1083+
10761084
CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode();
10771085
std::vector<SString> whitelist;
10781086
SString strData = result.pData;
10791087
strData.Split(";", whitelist);
1088+
1089+
if (whitelist.size() > 50000) [[unlikely]]
1090+
{
1091+
whitelist.resize(50000);
1092+
}
1093+
10801094
CXMLNode* pListNode = pRootNode->FindSubNode("globalwhitelist");
10811095
if (!pListNode)
10821096
return;
@@ -1119,10 +1133,21 @@ void CWebCore::StaticFetchBlacklistFinished(const SHttpDownloadResult& result)
11191133
if (!pWebCore->MakeSureXMLNodesExist())
11201134
return;
11211135

1136+
if (result.dataSize > 5 * 1024 * 1024) [[unlikely]]
1137+
{
1138+
return;
1139+
}
1140+
11221141
CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode();
11231142
std::vector<SString> blacklist;
11241143
SString strData = result.pData;
11251144
strData.Split(";", blacklist);
1145+
1146+
if (blacklist.size() > 50000) [[unlikely]]
1147+
{
1148+
blacklist.resize(50000);
1149+
}
1150+
11261151
CXMLNode* pListNode = pRootNode->FindSubNode("globalblacklist");
11271152
if (!pListNode)
11281153
return;

0 commit comments

Comments
 (0)