Issue 13534 - std.variant can violate memory safety
Summary: std.variant can violate memory safety
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull, safe
Depends on:
Blocks:
 
Reported: 2014-09-26 08:33 UTC by Tomoya Tanjo
Modified: 2017-07-19 17:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomoya Tanjo 2014-09-26 08:33:26 UTC
The following code can be compiled in dmd  v2.067-devel-590d4a9 but it should not.

------
import std.variant;

void main() @safe {
    auto foo() @system { return 3; }
    auto v = Variant(&foo);

    v(); // foo is called in safe code!?
}
------

Currently whole part of std.variant is marked as trusted but it should not because the safety of the functions or methods in this module
depends on the components which are stored in VariantN, Algebraic etc.
Comment 1 hsteoh 2014-09-26 19:31:12 UTC
Yeah, only those parts of Variant that deal with casting between types should be considered as @trusted; it's a very bad idea to make a whole big block of code @trusted when its actual semantics depends on arbitrary template parameters.
Comment 2 hsteoh 2014-09-26 19:36:32 UTC
Probably the most straightforward way to fix this bug is to remove @trusted: from the top of the module, and then incrementally add @trusted around the smallest possible code units until the Phobos test suite passes.
Comment 4 github-bugzilla 2015-04-27 11:49:39 UTC
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/38a29b2d56e91404bfe860b54b699783347b0ea5
remove "@trusted:" from std.variant

It's too broad.

This fixes issue 13534 - std.variant can violate memory safety.
Comment 5 github-bugzilla 2017-07-19 17:43:11 UTC
Commit pushed to dmd-cxx at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/38a29b2d56e91404bfe860b54b699783347b0ea5
remove "@trusted:" from std.variant