Bug 14137 – std.socket.getAddressInfo breaks @safety

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-02-07T01:06:00Z
Last change time
2016-04-18T13:51:43Z
Keywords
pull, safe
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-02-07T01:06:14Z
--- struct Oops { const(char[]) convert() { *cast(int*)0xcafebabe = 0xdeadbeef; return null; } alias convert this; } void main() @safe { import std.socket; getAddressInfo("", Oops.init); } --- Seems to be Git master (to-be 2.067) only. Source permalink: https://github.com/D-Programming-Language/phobos/blob/master/std/socket.d#L996-L997 Introduced in https://github.com/D-Programming-Language/phobos/pull/2316.
Comment #1 by code — 2015-02-07T12:33:49Z
Comment #2 by hsteoh — 2016-02-18T06:18:55Z
This is very bad. getAddressInfo() takes an ARBITRARY TYPE for its `options` parameter, yet it's marked @trusted ??! That's clearly ridiculous. What we need is a @safe unittest to ensure that it does not add any non-safety in the function body, but let the compiler determine whether the resulting combination with T is actually @safe. Unfortunately, even this is not enough, because getAddressInfoImpl is @system, so we need to wrap the call to it in a @trusted nested function. Ugh.
Comment #3 by hsteoh — 2016-02-18T06:21:52Z
The sheer amount of @trusted functions in std.socket is utterly frightening. How sure are we that this code is adequately reviewed??
Comment #4 by hsteoh — 2016-02-18T06:43:50Z
Comment #5 by github-bugzilla — 2016-04-18T13:51:43Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/c35d4aa26efd0907ccb48d7406dffc50f470971c Fix issue 14137: std.socket.getAddressInfo breaks @safe Remove abuse of @trusted in template function getAddressInfo that cannot guarantee that the incoming type argument is @safe. Localize @trusted block of the function to the single call to getAddressInfoImpl(), so that any @system code in T will be caught by the type system. Add unittest to ensure such examples of T will be rejected at compile-time. Mark normal unittest for getAddressInfo as @safe to ensure that the function body itself does not introduce any non-@safe code. https://github.com/dlang/phobos/commit/8a3453129f57a9db19c15026d184fc4e9da18ac3 Merge pull request #4009 from quickfur/issue14137 Fix issue 14137: std.socket.getAddressInfo breaks @safe