[Issue 20872] New: std.array.assocArray trusts user-provided 'front' for values

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 28 12:04:24 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20872

          Issue ID: 20872
           Summary: std.array.assocArray trusts user-provided 'front' for
                    values
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Keywords: safe
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: pro.mathias.lang at gmail.com

```
import std.array;

struct KeyRange
{
    @safe:
    string front () const { return null; }
    void popFront() {}
    bool empty() const { return false; }
}

struct ValueRange
{
    string front () const @system { int* ptr = cast(int*)42; *ptr = 42; return
null; }
    @safe:
    void popFront() {}
    bool empty() const { return false; }
}

void main () @safe
{
    KeyRange keys;
    ValueRange values;
    auto ret = assocArray(keys, values);
}
```

```
% dmd -preview=dip1000 -run foo.d
Error: program killed by signal 11
```

--


More information about the Digitalmars-d-bugs mailing list