diff --git a/src/AsyncLogger.h b/src/AsyncLogger.h index 5c2ccdc..76a54f0 100644 --- a/src/AsyncLogger.h +++ b/src/AsyncLogger.h @@ -12,7 +12,7 @@ class AsyncLogger { public: - AsyncLogger() : exitFlag(false) { + AsyncLogger() : exitFlag(false), queueFullWarningShown(false) { worker = std::thread([this] { processQueue(); }); @@ -32,17 +32,27 @@ class AsyncLogger { void log(const std::string& message) { { std::lock_guard lock(queueMutex); + if (msgQueue.size() >= MAX_QUEUE_SIZE) { + if (!queueFullWarningShown) { + std::cerr << "[Security] AsyncLogger queue full (" << MAX_QUEUE_SIZE + << " messages). Dropping logs to prevent DoS.\n"; + queueFullWarningShown = true; + } + return; + } msgQueue.push(message); } cv.notify_one(); } private: + const size_t MAX_QUEUE_SIZE = 10000; std::thread worker; std::queue msgQueue; std::mutex queueMutex; std::condition_variable cv; bool exitFlag; + bool queueFullWarningShown; void processQueue() { while (true) { @@ -63,6 +73,11 @@ class AsyncLogger { std::cout << msg << std::flush; lock.lock(); } + + // Reset warning flag when queue is empty + if (msgQueue.empty()) { + queueFullWarningShown = false; + } } } }; diff --git a/src/main.cpp b/src/main.cpp index 3503741..a1772aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,10 +187,6 @@ class RacingEngine { // Async Logger AsyncLogger logger; - // UX State Tracking - float currentFPS = 0.0f; - float frameTimeMs = 0.0f; - void updateWindowTitle() { glm::vec3 pos = camera.getPosition(); char title[512];