Bug 13534 – std.variant can violate memory safety

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-26T08:33:00Z
Last change time
2017-07-19T17:43:11Z
Keywords
accepts-invalid, pull, safe
Assigned to
nobody
Creator
ttanjo

Comments

Comment #0 by ttanjo — 2014-09-26T08:33:26Z
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 by hsteoh — 2014-09-26T19:31:12Z
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 by hsteoh — 2014-09-26T19:36:32Z
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 #3 by ag0aep6g — 2015-04-25T19:21:50Z
Comment #4 by github-bugzilla — 2015-04-27T11:49:39Z
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 by github-bugzilla — 2017-07-19T17:43:11Z