Skip to content

swift: write inside withUnsafeBytes in OutgoingConnection.send - #70

Open
mattt wants to merge 1 commit into
tailscale:mainfrom
mattt:mattt/fix-outgoing-send
Open

mattt wants to merge 1 commit into
tailscale:mainfrom
mattt:mattt/fix-outgoing-send

Conversation

@mattt

@mattt mattt commented Oct 28, 2026

Copy link
Copy Markdown

OutgoingConnection.send passes a pointer out of withUnsafeBytes and then writes from it. In optimized builds, short messages can arrive as the wrong bytes.

This PR does the write inside the closure, so the pointer stays valid while write uses it, and adds a test that sends a four-byte message through the existing connection test and checks the exact bytes received.

#55 also rewrites this line and the connection tests, and keeps the escaped pointer, so the closure form should survive whichever lands first.

Fixes tailscale/tailscale#22025

The data pointer escaped withUnsafeBytes before write used it, which
could send incorrect bytes for short messages in optimized builds.
Perform the write inside the closure to keep the pointer valid.

Fixes tailscale/tailscale#22025

Signed-off-by: Mattt Zmuda <mattt@me.com>
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.

libtailscale/TailscaleKit: OutgoingConnection.send uses a pointer outside withUnsafeBytes

1 participant