Server: fix idle CPU busy-loop and network-reachable memory-safety bugs - #251
Open
Leproide wants to merge 1 commit into
Open
Server: fix idle CPU busy-loop and network-reachable memory-safety bugs#251Leproide wants to merge 1 commit into
Leproide wants to merge 1 commit into
Conversation
Performance: - Main loop used usleep(1) with a non-blocking enet_host_service(..., 0), so it spun millions of times per second and burned about 20% of a core while idle with no clients. Raise the sleep to usleep(1000) (1 ms). A 1 ms tick is far finer than the 30/60 fps network rate; measured idle CPU dropped from about 22% to about 2%. Network-reachable memory safety (unauthenticated peer, single UDP packet): - CG_JOINROOM accepted room == 16, indexing roomInfos[16] one past the 16-entry array and writing through it. Reject room >= 16. - ProcessReceiveEvent cast packet->data to message structs without checking packet->dataLength, allowing out-of-bounds reads from truncated packets (reachable pre-join for CG_JOINROOM). Validate the minimum length per type. Hardening: - Player name is now NUL terminated server-side and printed with a bounded %.*s, preventing an over-read of client-controlled bytes. - Use fprintf(stderr, ...) instead of printf(stderr, ...). - Print build date/time and strftime output through explicit "%s" formats. - Check malloc return values in AddPeerLPL and AddIPBanL. No wire-format or gameplay changes.
This was referenced Aug 9, 2026
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.
Performance:
Network-reachable memory safety (unauthenticated peer, single UDP packet):
Hardening:
No wire-format or gameplay changes.