Skip to content

ICE: Don't pass a null pointer to memcpy for zero-length STUN attributes - #479

Open
smhussa22 wants to merge 1 commit into
ValveSoftware:masterfrom
smhussa22:ice-fix-ub-zerolen-memcpy
Open

smhussa22 wants to merge 1 commit into
ValveSoftware:masterfrom
smhussa22:ice-fix-ub-zerolen-memcpy

Conversation

@smhussa22

@smhussa22 smhussa22 commented Nov 19, 2026 •

Copy link
Copy Markdown

WriteGenericSTUNAttribute called V_memcpy with a null source pointer when writing a zero-length attribute (e.g. USE-CANDIDATE, built with m_nLength = 0 and m_pData = nullptr). Passing a null pointer to memcpy is undefined behavior per the C standard even when the count is 0.*

Verification

Built with -DSANITIZE_ADDRESS=ON -DSANITIZE_UNDEFINED=ON, running the unmodified test_p2p.py:

  • Before (master): UBSan reports strtools.h:47:116: runtime error: null pointer passed as argument 2, which is declared to never be null from WriteGenericSTUNAttribute → EncodeSTUNPacket → Think_TestPeerConnectivity, 26 times in one run (once per nominated candidate pair).
  • After (this branch): zero occurrences of that error in the same run.

test_crypto and test_p2p.py (TEST SUCCEEDED) pass on both builds. test_connection suite-quick aborts on an unrelated, pre-existing timing-sensitive assert that reproduces identically on unmodified master.

*Source, technically this was UB on every nominated candidate pair, even though it never caused an observable crash on this platform.

WriteGenericSTUNAttribute called V_memcpy with a null source pointer when
writing a zero-length attribute (e.g. USE-CANDIDATE). memcpy with a null
pointer is undefined behavior even when the count is 0. UBSan reports it
as 'null pointer passed as argument 2, which is declared to never be
null' on every nominated candidate pair.

Only copy when the length is non-zero.
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