Fix sendmsg/recvmsg data corruption in bsdsocket emulation#1790
Merged
midwan merged 1 commit intoBlitterStudio:masterfrom Feb 16, 2026
Merged
Fix sendmsg/recvmsg data corruption in bsdsocket emulation#1790midwan merged 1 commit intoBlitterStudio:masterfrom
midwan merged 1 commit intoBlitterStudio:masterfrom
Conversation
sendmsg() sent data from the wrong buffer because host_sendto() always used get_real_address(msg) for sb->buf, ignoring the pre-computed realpt variable. When called from bsdsocklib_sendmsg(), msg is 0 (not an Amiga buffer address) and hmsg points to the coalesced iovec data. The worker thread received natmem_offset+0 (start of Amiga RAM) instead of the actual data buffer, silently corrupting all sendmsg transfers. Also fixes two secondary bugs in the sendmsg/recvmsg trap handlers: - sendmsg passed the Amiga address of msg_namelen as tolen instead of reading its value, breaking UDP sendmsg with a destination address - recvmsg used ftable[sd-1] with 0-based sd, causing an off-by-one in MSG_TRUNC detection (out-of-bounds for socket 0) Validated with bsdsocktest 0.2.2 (142 tests): - Before: 116 passed, 11 known failures - After: 130 passed, 9 known failures (with host helper) - Tests fixed: 31 (sendmsg single iovec), 32 (sendmsg scatter-gather) - No regressions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
midwan
approved these changes
Feb 16, 2026
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.
Problem
sendmsg()in the bsdsocket emulation silently sent data from the wrong memory location. Thehost_sendto()function (POSIX path) always assignedsb->buf = get_real_address(msg)regardless of whether a host-side buffer was provided viahmsg. When called frombsdsocklib_sendmsg(),msgis 0 andhmsgpoints to the coalesced iovec data — soget_real_address(0)resolved tonatmem_offset(Amiga address 0) instead of the actual data buffer. The worker thread then sent whatever was at the start of Amiga chip RAM.Two additional bugs existed in the sendmsg/recvmsg trap handlers:
bsdsocklib_sendmsg()passed the Amiga address of themsg_namelenfield astolentohost_sendto(), but the worker thread usestolenas a length value. This broke UDPsendmsg()with a destination address, sincecopysockaddr_a2n()received a multi-million-byte "length" and rejected it.bsdsocklib_recvmsg()usedftable[sd - 1]with a 0-based socket descriptor, causing an off-by-one inMSG_TRUNCdetection. For socket 0 this was an out-of-bounds read (ftable[-1]); for all others it checked the wrong socket's flags.Fix
Three targeted changes:
host_sendto(): Userealpt(which already handles both the normalsend/sendtopath and thesendmsgpath) instead of unconditionally callingget_real_address(msg). This matches howhost_recvfrom()already works.bsdsocklib_sendmsg(): Read themsg_namelenvalue withtrap_get_long()before passing tohost_sendto(), consistent with how normalsendto()passestolenfrom the D3 register.bsdsocklib_recvmsg(): Useftable[sd]instead offtable[sd - 1]for correct 0-based indexing.Validation
Tested with bsdsocktest 0.2.2 (142 tests):
Tests fixed: 31 (sendmsg/recvmsg single iovec), 32 (sendmsg/recvmsg scatter-gather). No regressions across all 142 tests.
🤖 Generated with Claude Code