Skip to content

Commit 48fd939

Browse files
Synchronize changes from 1.6 master branch [ci skip]
1532130 Revert PR #3620 (Read file from path) due to bugs persisting
2 parents 41a646b + 1532130 commit 48fd939

File tree

8 files changed

+68
-294
lines changed

8 files changed

+68
-294
lines changed

Client/mods/deathmatch/logic/CScriptFile.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
158158
DoResourceFileCheck();
159159

160160
// If read size is large, limit it to how many bytes can be read (avoid memory problems with over allocation)
161-
// large : >10KB
162-
if (ulSize > 10240)
161+
if (ulSize > 10000)
163162
{
164163
long lCurrentPos = m_pFile->FTell();
165164
m_pFile->FSeek(0, SEEK_END);
@@ -178,18 +177,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
178177
return -2;
179178
}
180179

181-
auto bytesRead = m_pFile->FRead(outBuffer.data(), ulSize);
182-
183-
// EOF reached?
184-
// Cant check for error as binary interface
185-
// is pure virtual class with no definitions
186-
// available (CNetServer)
187-
if (m_pFile->FEof())
188-
{
189-
// if so, truncate the data to the amount of bytes read
190-
outBuffer.resize(bytesRead + 1);
191-
}
192-
return bytesRead;
180+
return m_pFile->FRead(outBuffer.data(), ulSize);
193181
}
194182

195183
long CScriptFile::Write(unsigned long ulSize, const char* pData)

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,6 @@ void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisRe
12681268
// No operation on the client
12691269
}
12701270

1271-
std::pair<bool, std::string> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept
1272-
{
1273-
return {true, ""};
1274-
}
1275-
12761271
//
12771272
// Set error if pThisResource does not have permission to modify every resource in resourceList
12781273
//
@@ -1281,11 +1276,6 @@ void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisR
12811276
// No operation on the client
12821277
}
12831278

1284-
std::pair<bool, std::string> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept
1285-
{
1286-
return {true, ""};
1287-
}
1288-
12891279
//
12901280
// Set error if resource file access is blocked due to reasons
12911281
//
@@ -1294,8 +1284,3 @@ void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pTh
12941284
{
12951285
// No operation on the client
12961286
}
1297-
1298-
std::pair<bool, std::string> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly) noexcept
1299-
{
1300-
return {true, ""};
1301-
}

Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,9 @@ void ReadPregFlags(CScriptArgReader& argStream, pcrecpp::RE_Options& pOptions);
590590
// Resource access helpers
591591
//
592592
void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource);
593-
std::pair<bool, std::string> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept;
594593
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
595-
std::pair<bool, std::string> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept;
596-
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
594+
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
597595
bool* pbReadOnly = nullptr);
598-
std::pair<bool, std::string> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
599-
bool* pbReadOnly = nullptr) noexcept;
600596

601597
//
602598
// Other misc helpers

Server/mods/deathmatch/logic/CScriptFile.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
178178
return -1;
179179

180180
// If read size is large, limit it to how many bytes can be read (avoid memory problems with over allocation)
181-
// large : >10KB
182-
if (ulSize > 10240)
181+
if (ulSize > 10000)
183182
{
184183
long lCurrentPos = ftell(m_pFile);
185184
fseek(m_pFile, 0, SEEK_END);
@@ -198,15 +197,7 @@ long CScriptFile::Read(unsigned long ulSize, SString& outBuffer)
198197
return -2;
199198
}
200199

201-
auto bytesRead = fread(outBuffer.data(), 1, ulSize, m_pFile);
202-
203-
// EOF reached or error was thrown?
204-
if (feof(m_pFile) || ferror(m_pFile))
205-
{
206-
// if so, truncate the data to the amount of bytes read
207-
outBuffer.resize(bytesRead + 1);
208-
}
209-
return bytesRead;
200+
return fread(outBuffer.data(), 1, ulSize, m_pFile);
210201
}
211202

212203
long CScriptFile::Write(unsigned long ulSize, const char* pData)

Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.cpp

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -746,17 +746,6 @@ void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisRe
746746
"Access denied");
747747
}
748748

749-
std::pair<bool, SString> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept
750-
{
751-
if (GetResourceModifyScope(pThisResource, pOtherResource) != eResourceModifyScope::NONE)
752-
return {true, ""};
753-
754-
SString str("ModifyOtherObjects in ACL denied resource %s to access %s",
755-
pThisResource->GetName().c_str(), pOtherResource->GetName().c_str()
756-
);
757-
return {false, str};
758-
}
759-
760749
//
761750
// Set error if pThisResource does not have permission to modify every resource in resourceList
762751
//
@@ -798,46 +787,6 @@ void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisR
798787
SString("ModifyOtherObjects in ACL denied resource %s to access %s", pThisResource->GetName().c_str(), ssResourceNames.str().c_str()), "Access denied");
799788
}
800789

801-
std::pair<bool, SString> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept
802-
{
803-
// std::unordered_set only allows unique values and resourceList can contain duplicates
804-
std::unordered_set<CResource*> setNoPermissionResources;
805-
806-
for (const auto& pOtherResource : resourceList)
807-
{
808-
eResourceModifyScope modifyScope = GetResourceModifyScope(pThisResource, pOtherResource);
809-
810-
if (modifyScope == eResourceModifyScope::SINGLE_RESOURCE)
811-
continue;
812-
813-
if (modifyScope == eResourceModifyScope::EVERY_RESOURCE)
814-
return {true, ""};
815-
816-
setNoPermissionResources.emplace(pOtherResource);
817-
}
818-
819-
if (setNoPermissionResources.empty())
820-
return {true, ""};
821-
822-
std::stringstream ssResourceNames;
823-
std::size_t remainingElements = setNoPermissionResources.size();
824-
825-
for (const auto& pResource : setNoPermissionResources)
826-
{
827-
ssResourceNames << pResource->GetName();
828-
829-
if (remainingElements > 1)
830-
ssResourceNames << ", ";
831-
832-
--remainingElements;
833-
}
834-
835-
SString str("ModifyOtherObjects in ACL denied resource %s to access %s",
836-
pThisResource->GetName().c_str(), ssResourceNames.str().c_str()
837-
);
838-
return {false, str};
839-
}
840-
841790
//
842791
// Set error if resource file access is blocked due to reasons
843792
//
@@ -864,28 +813,3 @@ void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pTh
864813
SString("Database credentials protection denied resource %s to access %s", *pThisResource->GetName(), *pOtherResource->GetName()), "Access denied");
865814
}
866815
}
867-
868-
std::pair<bool, SString> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly) noexcept
869-
{
870-
if (!g_pGame->GetConfig()->IsDatabaseCredentialsProtectionEnabled())
871-
return {true, ""};
872-
873-
// Is other resource different and requested access denied
874-
if (pThisResource == pOtherResource)
875-
return {true, ""};
876-
877-
if (!pOtherResource->IsFileDbConnectMysqlProtected(strAbsPath, pbReadOnly ? *pbReadOnly : false))
878-
return {true, ""};
879-
880-
// No access - See if we can change to readonly
881-
if (pbReadOnly && !(*pbReadOnly) && !pOtherResource->IsFileDbConnectMysqlProtected(strAbsPath, true)) {
882-
// Yes readonly access
883-
*pbReadOnly = true;
884-
return {true, ""};
885-
}
886-
887-
SString str("Database credentials protection denied resource %s to access %s",
888-
*pThisResource->GetName(), *pOtherResource->GetName()
889-
);
890-
return {false, str};
891-
}

Server/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,9 @@ enum class eResourceModifyScope
403403

404404
eResourceModifyScope GetResourceModifyScope(CResource* pThisResource, CResource* pOtherResource);
405405
void CheckCanModifyOtherResource(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource);
406-
std::pair<bool, SString> CheckCanModifyOtherResource(CResource* pThisResource, CResource* pOtherResource) noexcept;
407-
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
408-
std::pair<bool, SString> CheckCanModifyOtherResources(CResource* pThisResource, std::initializer_list<CResource*> resourceList) noexcept;
406+
void CheckCanModifyOtherResources(CScriptArgReader& argStream, CResource* pThisResource, std::initializer_list<CResource*> resourceList);
409407
void CheckCanAccessOtherResourceFile(CScriptArgReader& argStream, CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath,
410408
bool* pbReadOnly = nullptr);
411-
std::pair<bool, SString> CheckCanAccessOtherResourceFile(CResource* pThisResource, CResource* pOtherResource, const SString& strAbsPath, bool* pbReadOnly = nullptr) noexcept;
412409

413410
//
414411
// Other misc helpers

0 commit comments

Comments
 (0)