Issue 15702: std.socket.Socket.receive can be @trusted only if buffer has no indirections #4011
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.
Anything that receives
void[]
and writes to it cannot be considered@trusted
, because passing in an array of element with indirections to, say,std.socket.Socket.receive
will cause overwriting of pointers with arbitrary network data.So rework the API not to throw away type information about the incoming array until we have checked whether it contains indirections. In order not to break code that needs to call
receive
on arrays with indirections, we still allow the call but it will be@system
instead of@trusted
. E.g., a multithreaded program that uses sockets to communicate between threads may be able to legitimately pass pointers via sockets. But since we cannot guarantee@safe
-ty in this case, such calls toreceive
will be@system
, and it's up to the user to verify that things work correctly and mark their own code as@trusted
where applicable.