From bfd406999434f6e24a441a2db5191a50df6745fd Mon Sep 17 00:00:00 2001 From: Reece Date: Tue, 18 Apr 2023 02:30:11 +0100 Subject: [PATCH] [*] logger mitigations cont - current thread callback may as well be sanitized as well --- Source/Logging/AuLogger.cpp | 81 ++++++++++++++++++++++++++----------- Source/Logging/AuLogger.hpp | 3 +- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/Source/Logging/AuLogger.cpp b/Source/Logging/AuLogger.cpp index 4cecebb6..c8b8bfaa 100644 --- a/Source/Logging/AuLogger.cpp +++ b/Source/Logging/AuLogger.cpp @@ -42,10 +42,7 @@ namespace Aurora::Logging (msg.line.find('\r') == AuString::npos && msg.line.find('\33') == AuString::npos))) [[likely]] { - if (WriteNow(uLevel, msg)) - { - AddToPushQueueConst(uLevel, msg); - } + WriteNowConst(uLevel, msg); } else [[unlikely]] { @@ -57,7 +54,7 @@ namespace Aurora::Logging if (WriteNow(uLevel, dup)) { - AddToPushQueue(uLevel, dup); + AddToPushQueueConst(uLevel, dup); } }); } @@ -92,19 +89,6 @@ namespace Aurora::Logging void Logger::AddToPushQueue(AuUInt8 uLevel, /*const*/ ConsoleMessage &msg) { - if (this->bEnableMitigations) - { - if (msg.line.find('\r') != AuString::npos) [[unlikely]] - { - AuReplaceAll(msg.line, "\r", "\\r"); - } - - if (msg.line.find('\33') != AuString::npos) [[unlikely]] - { - AuReplaceAll(msg.line, "\33", "\\e"); - } - } - AddToPushQueueConst(uLevel, msg); } @@ -307,9 +291,11 @@ namespace Aurora::Logging } } - bool Logger::WriteNow(AuUInt8 uLevel, const ConsoleMessage &msg) + + void Logger::WriteNowConst(AuUInt8 uLevel, const ConsoleMessage &msg) { - bool ret {}; + bool bDelegateLater {}; + try { for (const auto &sink : this->sinks) @@ -321,7 +307,7 @@ namespace Aurora::Logging try { - ret |= sink->OnMessageNonblocking(uLevel, msg); + bDelegateLater |= sink->OnMessageNonblocking(uLevel, msg); } catch (...) { @@ -331,10 +317,58 @@ namespace Aurora::Logging } catch (...) { - ret = true; + bDelegateLater = true; SysPushErrorCatch(); } - return ret; + + if (bDelegateLater) + { + AddToPushQueueConst(uLevel, msg); + } + } + + bool Logger::WriteNow(AuUInt8 uLevel, ConsoleMessage &msg) + { + if (this->bEnableMitigations) + { + if (msg.line.find('\r') != AuString::npos) [[unlikely]] + { + AuReplaceAll(msg.line, "\r", "\\r"); + } + + if (msg.line.find('\33') != AuString::npos) [[unlikely]] + { + AuReplaceAll(msg.line, "\33", "\\e"); + } + } + + bool bDelegateLater {}; + try + { + for (const auto &sink : this->sinks) + { + if (!sink) + { + continue; + } + + try + { + bDelegateLater |= sink->OnMessageNonblocking(uLevel, msg); + } + catch (...) + { + SysPushErrorCatch("Failed to pump a logger"); + } + } + } + catch (...) + { + bDelegateLater = true; + SysPushErrorCatch(); + } + + return bDelegateLater; } void Logger::WriteLater(AuUInt8 uLevel, const ConsoleMessage &msg) @@ -366,7 +400,6 @@ namespace Aurora::Logging void InitLoggers() { - gLogTasks.reserve(1000); } diff --git a/Source/Logging/AuLogger.hpp b/Source/Logging/AuLogger.hpp index 1480a377..7b5a9a93 100644 --- a/Source/Logging/AuLogger.hpp +++ b/Source/Logging/AuLogger.hpp @@ -26,7 +26,8 @@ namespace Aurora::Logging void AddToPushQueueConst(AuUInt8 level, const ConsoleMessage &msg); void AddToPushQueue(AuUInt8 level, ConsoleMessage &msg); - bool WriteNow(AuUInt8 level, const ConsoleMessage &msg); + bool WriteNow(AuUInt8 level, ConsoleMessage &msg); + void WriteNowConst(AuUInt8 level, const ConsoleMessage &msg); void WriteLater(AuUInt8 level, const ConsoleMessage &msg); void WriteLines(AuUInt8 level, const ConsoleMessage &msg);