[*] Exceptionless-API hardening

This commit is contained in:
Reece Wilson 2023-12-22 00:17:19 +00:00
parent 298b095cc1
commit 66eca9ff8f
3 changed files with 181 additions and 118 deletions

View File

@ -50,12 +50,15 @@ namespace Aurora::IO::FS
virtual StatEx *Next() override
{
StatEx *pNext {};
if (!this->pDir)
{
return {};
}
auto pNext = this->pDir->Next();
try
{
pNext = this->pDir->Next();
while (!pNext)
{
DoNext();
@ -85,6 +88,11 @@ namespace Aurora::IO::FS
this->failedPaths.push_back(pNext->fileName);
}
}
}
catch (...)
{
SysPushErrorCatch();
}
return pNext;
}
@ -107,6 +115,8 @@ namespace Aurora::IO::FS
auto pObj = AuMakeShared<RecursiveDirDeleter>();
SysCheckNotNullMemory(pObj, false);
try
{
if (!pObj->OpenDir(string))
{
return {};
@ -120,6 +130,12 @@ namespace Aurora::IO::FS
pObj->RemoveDirs();
AuFS::Remove(string);
}
catch (...)
{
SysPushErrorCatch();
}
return !AuFS::DirExists(string);
}
@ -128,6 +144,8 @@ namespace Aurora::IO::FS
auto pObj = AuMakeShared<RecursiveDirDeleter>();
SysCheckNotNullMemory(pObj, false);
try
{
if (!pObj->OpenDir(string))
{
return {};
@ -167,6 +185,11 @@ namespace Aurora::IO::FS
return false;
}
}
catch (...)
{
SysPushErrorCatch();
}
return true;
}

View File

@ -48,12 +48,15 @@ namespace Aurora::IO::FS
virtual StatEx *Next() override
{
StatEx *pNext {};
if (!this->pDir)
{
return {};
}
auto pNext = this->pDir->Next();
try
{
pNext = this->pDir->Next();
while (!pNext)
{
DoNext();
@ -74,6 +77,11 @@ namespace Aurora::IO::FS
{
nextLevel.push_back(pNext->fileName + "/");
}
}
catch (...)
{
SysPushErrorCatch();
}
return pNext;
}
@ -88,10 +96,17 @@ namespace Aurora::IO::FS
return {};
}
try
{
if (!pObj->OpenDir(string))
{
return {};
}
}
catch (...)
{
SysPushErrorCatch();
}
return pObj;
}

View File

@ -20,15 +20,22 @@ namespace Aurora::Process
{
AUKN_SYM bool GetWorkingDirectory(AuString &path)
{
#if !defined(AURORA_IS_MODERNNT_DERIVED)
if (!AuTryResize(path, 0x4000))
{
return false;
}
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
std::wstring eh;
eh.resize(path.size());
if (!AuTryResize(eh, 0x4000))
{
return false;
}
auto length = ::GetCurrentDirectoryW(eh.size(), eh.data());
if (length == 0)
@ -36,12 +43,20 @@ namespace Aurora::Process
return false;
}
path = Locale::ConvertFromWChar(eh.data(), length);
path = AuMove(Locale::ConvertFromWChar(eh.data(), length));
try
{
if (!path.ends_with(AuFS::kPathSplitter))
{
path += AuFS::kPathSplitter;
}
}
catch (...)
{
SysPushErrorCatch();
return false;
}
return true;
@ -174,45 +189,55 @@ namespace Aurora::Process
static bool GetModulePath(const AuString *&module, const AuString *&partialPath, const AuString *&fullPath)
{
static AuString cachedModule, cachedPartialPath, cachedFullPath;
static bool init = false;
static AuThreadPrimitives::SpinLock spinlock;
static AuInitOnce gInitOnce;
static bool bFailed {};
if (!AuThreading::InitOnceLocker::TryLock(&gInitOnce, true))
{
gInitOnce.Wait();
}
else
{
try
{
char spitter;
AU_TRY_LOCK_GUARD_RET_DEF(spinlock);
if (AuExchange(init, true))
{
if (!cachedModule.size())
{
return false;
}
goto returnCached;
}
if (!GetModulePathSlow(cachedFullPath, spitter))
{
return false;
}
// this scope is required for c++20, bleh
if (GetModulePathSlow(cachedFullPath, spitter))
{
auto indexA = cachedFullPath.find_last_of(spitter);
if (indexA == AuString::npos)
if (indexA != AuString::npos)
{
return false;
}
cachedModule = cachedFullPath.substr(indexA + 1);
cachedPartialPath = cachedFullPath.substr(0, indexA);
}
else
{
bFailed = true;
}
if (!cachedPartialPath.ends_with(AuFS::kPathSplitter))
{
cachedPartialPath += AuFS::kPathSplitter;
}
}
else
{
bFailed = true;
}
}
catch (...)
{
bFailed = true;
SysPushErrorCatch();
}
returnCached:
AuThreading::InitOnceLocker::Finish(&gInitOnce, bFailed);
}
if (bFailed)
{
return false;
}
module = &cachedModule;
fullPath = &cachedFullPath;