Skip to content

Issue 15702: std.socket.Socket.receive can be @trusted only if buffer has no indirections #4011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

quickfur
Copy link
Member

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 to receive 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.

… has no indirections.

Anything that receives void[] and writes to it cannot be considered
@trusted, because passing in an array of element with indirections will
cause overwriting of pointers with arbitrary network data.
@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
15702 std.socket.Socket.receive breaks @safe

@JakobOvrum
Copy link
Member

Basically every I/O API, present and future, has this issue. I'd rather we make one small change to the language than complicating a crapload of library APIs.

@quickfur
Copy link
Member Author

And what would that language change be?

@adamdruppe
Copy link
Contributor

This would break my SSL socket because it depends on receive being virtual.

It would be better to keep void[] and just fix the language so types with indirections are not implicitly casted when you are calling a @safe function.

@quickfur
Copy link
Member Author

@adamdruppe Hmm, you're right, I hadn't thought of class inheritance. :-( Looks like what's really needed here is a compiler fix. I'll look into that.

@JakobOvrum
Copy link
Member

And what would that language change be?

You've already read it at least once.


This would also break Dirk's SSL socket for the same reason it would break @adamdruppe's - it overrides receive.

@quickfur
Copy link
Member Author

Makes sense. Looking into the compiler code right now. So basically we'll allow implicit conversion of T[] to void[] for any T when in @system code, but in @safe code we only allow it if T has no indirections. Allowing in @system code means people can still circumvent it when necessary, but @safe code will complain loudly that something's amiss.

@quickfur quickfur closed this Feb 19, 2016
@quickfur quickfur deleted the issue15702 branch February 19, 2016 21:11
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.

4 participants