Skip to content

Comments

fix(forwarder): null-check allocations and fix resource leaks in quicforward#5807

Open
MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
MarkedMuichiro:fix/quicforward-null-alloc
Open

fix(forwarder): null-check allocations and fix resource leaks in quicforward#5807
MarkedMuichiro wants to merge 1 commit intomicrosoft:mainfrom
MarkedMuichiro:fix/quicforward-null-alloc

Conversation

@MarkedMuichiro
Copy link

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:

  • ListenerCallback returns QUIC_STATUS_OUT_OF_MEMORY on allocation failure.
    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.
  • ConnectionCallback explicitly closes the raw stream handle on allocation
    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.

…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
@MarkedMuichiro MarkedMuichiro requested a review from a team as a code owner February 21, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant