Repository navigation
Conversation
fdlist_add() assigned the results of realloc() directly to list->owners and list->fds and doubled the capacity unconditionally, so on out-of-memory the arrays were leaked and the following stores wrote through a NULL pointer, crashing the daemon. Only update the pointers and the capacity once the reallocation succeeded. If it fails, log an error and leave the fd out of this poll() round; the main loop rebuilds the list on every iteration. A capacity of 0 (after fdlist_free()) now grows to 4 instead of staying 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
fdlist_add()doubleslist->capacityand assigns the results ofrealloc()directly tolist->ownersandlist->fds. Whenrealloc()fails, the arrays are leaked and the following stores write through a NULL pointer, which crashes the daemon.This only updates the pointers and the capacity once the reallocation succeeded. On failure it logs an error and leaves the fd out of this
poll()round; the main loop rebuilds the list on every iteration, so it is picked up again next time. If only the secondrealloc()fails,ownersis simply larger than needed, which is harmless. A capacity of 0 (afterfdlist_free()) now grows to 4 instead of staying 0.Testing:
fdlist_create()/fdlist_add()/fdlist_free()copied verbatim from3ded00cand from this branch, run under ASan+UBSan; fill the list to its capacity of 4, then make the next growth fail:realloc()ofownersfails: before SEGV, after the fd is skipped and the next add succeeds (count=5, fds10,11,12,13,100)realloc()offdsfails: samecount=6 cap=8)🤖 Generated with Claude Code