[dmd-internals] [D-Programming-Language/dmd] 6ef6b7: Fixes Issue 5385 - Access must be checked for stat...

kenji hara k.hara.pg at gmail.com
Sat Dec 22 03:02:32 PST 2012


2012/12/22 Rainer Schuetze <r.sagitario at gmx.de>

> On 19.12.2012 05:54, GitHub wrote:
>
>>    Branch: refs/heads/master
>>    Home:   https://github.com/D-**Programming-Language/dmd<https://github.com/D-Programming-Language/dmd>
>>    Commit: 6ef6b721642be8cb5a9ffbcef6f80d**92fc071bc5
>>        https://github.com/D-**Programming-Language/dmd/**commit/**
>> 6ef6b721642be8cb5a9ffbcef6f80d**92fc071bc5<https://github.com/D-Programming-Language/dmd/commit/6ef6b721642be8cb5a9ffbcef6f80d92fc071bc5>
>>    Author: Andrej Mitrovic <andrej.mitrovich at gmail.com>
>>    Date:   2012-12-18 (Tue, 18 Dec 2012)
>>
>>    Changed paths:
>>      M src/mtype.c
>>      A test/fail_compilation/**diag5385.d
>>      A test/fail_compilation/imports/**fail5385.d
>>
>>    Log Message:
>>    -----------
>>    Fixes Issue 5385 - Access must be checked for static and __gshared
>> fields.
>>
>
> This patch seems to have broken my precise GC implementation: it causes
> compile time type reflection to fail for private members. A stripped down
> version of the problem is:
>
> /////////////////
> module s;
>
> struct S
> {
>         int x;
> private:
>         int p;
> }
>
> ////////////////
> module test;
> import s;
>
> void main()
> {
>     foreach(i, fieldName; (__traits(allMembers, S)))
>     {
>             size_t cur_offset = mixin("(S." ~ fieldName ~").offsetof");
>             alias typeof(mixin("S." ~ fieldName)) U; // line 9
>
>             pragma(msg,"  field " ~ fieldName ~ " : " ~ U.stringof);
>             //mkBitmap!U(p, offset + cur_offset);
>     }
> }
>
> "dmd -c test.d" now produces:
>   field x : int
> test.d(9): Error: struct s.S member p is not accessible
>   field p : int
>

Hmm..., this is interesting issue which could be debetable.


> Interestingly, getting offsetof doesn't cause problems (but that is
> probably a bug).


In the expression (S.field).offsetof, the part (S.field) is parsed as *a
type*. And current dmd implemtation does not run access check in the
resolving of dot-chained type identifier.
If you changed it to S.field.offsetof, access check will report an error.


> I understand that private members should not be accessible, but it also
> makes generating runtime type information for RTInfo!T difficult.
>
> Or maybe I am missing another way to get the type of a field?
>

Using tupleof can be a workaround.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20121222/00cea60e/attachment.html>


More information about the dmd-internals mailing list