refactor: optimize JSON handling, fix pointer safety, and improve overall stability - #15
Open
lozatto wants to merge 14 commits into
Open
refactor: optimize JSON handling, fix pointer safety, and improve overall stability#15lozatto wants to merge 14 commits into
lozatto wants to merge 14 commits into
Conversation
…send log events containing invalid UTF-8 characters (commonly found in player names or chat messages with special symbols). By default, the nlohmann/json library throws an unhandled exception when encountering malformed strings during the serialization process.
…o make the LogApi significantly more stable. The crash logs confirmed that the failure occurred during JSON serialization (dump_escaped), typically caused by invalid UTF-8 characters or null pointers.
…ication, and remote command execution
…response processing
Contributor
Author
|
@SmileYzn , I’m not sure if you had the opportunity to review the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces several stability improvements, memory optimizations, and crash preventions across the
LogApimodule. The main focus was to replace pass-by-value with constant references for complex JSON objects, prevent potential crashes from unvalidated engine strings/pointers, and fix an issue with malformed UTF-8 data serialization.🛠️ Key Changes
Performance & Memory Optimization:
Changed
nlohmann::ordered_jsonparameters from pass-by-value to pass-by-const-reference (const nlohmann::ordered_json&) across multiple functions (SendEvent,EventResult,ClientPrint, etc.) to eliminate redundant deep copies.Crash & Exploit Prevention:
Added
nlohmann::ordered_json::error_handler_t::replaceduringEvent.dump()serialization to gracefully handle and replace invalid UTF-8 characters, avoiding potential server crashes.Wrapped critical engine interactions and string conversions inside
try-catchblocks (std::exception) to catch generic failures beyond just JSON parse errors.Added strict null-pointer and validation checks for game engine entities and strings (
pvPrivateData,net_address,hostname,mapname).Bug Fixes & Refactoring:
Fixed a bug in
CLogPlayer::GetPlayerJsonby copying therawAuthengine pointer immediately into astd::string, preventing it from being invalidated by subsequent engine calls.Improved buffer safety in menu handling (
LogMenu.cpp) by enforcing explicit limits (MAX_BUFFER_MENU) and manual null-termination.Tuned
Makefileflags: added-fno-strict-aliasingand removed-static-libgcc -static-libstdc++from the linker to resolve potential binary compatibility issues on Linux.