fix(forwarder): null-check allocations and fix resource leaks in quicforward#5807
Open
MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(forwarder): null-check allocations and fix resource leaks in quicforward#5807MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…forward - Check MsQuicStream allocs in ConnectionCallback; close raw stream handle on failure instead of leaking it - Check MsQuicConnection allocs in ListenerCallback; return QUIC_STATUS_OUT_OF_MEMORY so MsQuic refuses connection cleanly - Free SendContext before CXPLAT_FRE_ASSERT fires on unexpected send errors in StreamCallback
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.
Description
Fixes #[5806].
In quicforward.cpp, MsQuicStream and MsQuicConnection objects are allocated with new(std::nothrow) in ConnectionCallback and ListenerCallback, but the results are never null-checked before being dereferenced. Under OOM conditions this causes a null pointer dereference and crash. The correct guard pattern already exists in MsQuicAutoAcceptListener in msquic.hpp and is applied here consistently.
Additionally, in StreamCallback, if StreamSend returns an unexpected error status, CXPLAT_FRE_ASSERT fires without first freeing SendContext, causing a resource leak before process termination. SendContext is now freed on all failure paths before the assert fires.
Ownership notes:
Confirmed via listener.c that failure returns are permitted — MsQuic
refuses the connection and retains handle ownership, so no manual cleanup
of the raw connection handle is needed.
failure, matching the pattern in spinquic.cpp. Sequential allocation is
intentional — MsQuicConnection's constructor calls SetCallbackHandler
immediately, so a consolidated null-check would risk closing a handle
not yet owned by the caller.
Testing
No existing tests cover these OOM paths. Built successfully on Linux (GitHub Codespaces) and validated normal forwarding behavior is unaffected. Reliably triggering these paths requires fault injection that does not currently exist for this code. Happy to add coverage if maintainers have a preferred approach.
Documentation
None.