Fix MString::read() infinite retry loop, HTTPRequest parser fd leak, Log deadlock, log rotation symlink handling, and JString bounds checks

- MString::read() now gives up after repeated I/O errors instead of
  looping forever and crashing via realloc() failure (root cause of a
  recurring barant.com production crash).
- HTTPRequest::parse() no longer leaks lineParser/headerParser on a
  malformed request.
- Log gained size-based rotation (config-driven) and a non-static-mutex
  fix; a separate fix stopped rotation from destroying the logs symlink
  on its first trigger.
- File.cpp: symlink-preserving rotation support.
- JString: fixed an array-index out-of-bounds and a setString issue.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Brad ArantandClaude Sonnet 5 committed 2026-10-06 17:38:14 +00:00
1 parent 694c6b80a4
commit 05374bdb15
7 files changed
+213 -14

No files matched your search

+27 -1
View File
@@ -89,8 +89,34 @@ namespace coreutils {
static int seq;
///
/// Rotation threshold for the static logFile, in bytes - checked
/// after every write that reaches it. Default 100MB. Change it
/// any time (takes effect on the next log call); 0 disables
/// rotation entirely.
///
static size_t maxLogSize;
///
/// How many rotated-out backups (logFile.1, logFile.2, ...) to
/// keep once maxLogSize is hit - the oldest beyond this count is
/// deleted outright, not just renamed away. Default 5.
///
static int maxLogBackups;
private:
std::mutex mtx;
// Static, not per-instance - every Log(level) call constructs
// and destructs its own temporary Log object, so a per-instance
// mutex (the original declaration here) provided no actual
// mutual exclusion between concurrent threads at all, each
// locking a separate mutex of their own. Only became load-bearing
// once rotation was added: two threads racing between "check
// size" and "close/rename/reopen" on the one shared logFile
// could otherwise write to a stale fd mid-rotation or rotate out
// from under an in-flight write.
static std::mutex mtx;
};