Refs pointing to differently annotated variables / fields creates dataflow hole
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
The linker has analysis holes around ref fields that easily allows annotated pointers to point to differently annotated variables / fields. This means a ref field with PublicMethods could point to a field with PublicMethods and PublicFields, then assign a value with PublicMethods but not PublicFields to the location.
Another example:
```C#
static void AnalysisHole<
T,
[DAMT.PublicMethods)] TM,
[DAM (DAMT.PublicMethods | DAMT.PublicFields)] TMF
>
(scoped RefFieldWithMethods target,
[DAMT.PublicMethods | DAMT.PublicFields)] Type tmf)
{
var tmLocal = typeof (TM);
target.T = ref tmLocal;
tmLocal = typeof (T); // Should warn for assigning and unannotated value to a location pointed to by an annotated pointer
target.T = ref tmf;
target.T = typeof (TM); // Should warn for assigning a value with only Methods to a location annotated with Methods and Fields
}
ref struct RefFieldWithMethods
{
[DynamicallyAccessedMembers (DAMT.PublicMethods)]
public ref Type T;
}
```
Related to https://github.com/dotnet/linker/issues/2158
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.