mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Merge pull request #12370 from michaelnebel/csharp/unsafemember
C#: Improve the `unsafe` predicate on Modifiable.
This commit is contained in:
4
csharp/ql/lib/change-notes/2023-03-02-unsafemembers.md
Normal file
4
csharp/ql/lib/change-notes/2023-03-02-unsafemembers.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* The `unsafe` predicate for `Modifiable` has been extended to cover delegate return types and identify pointer like types at any nest level. This is relevant for `unsafe` declarations extracted from assemblies.
|
||||
@@ -98,10 +98,21 @@ class Modifiable extends Declaration, @modifiable {
|
||||
|
||||
/** Holds if this declaration is `unsafe`. */
|
||||
predicate isUnsafe() {
|
||||
this.hasModifier("unsafe") or
|
||||
this.(Parameterizable).getAParameter().getType() instanceof PointerType or
|
||||
this.(Property).getType() instanceof PointerType or
|
||||
this.(Callable).getReturnType() instanceof PointerType
|
||||
this.hasModifier("unsafe")
|
||||
or
|
||||
exists(Type t, Type child |
|
||||
t = this.(Parameterizable).getAParameter().getType() or
|
||||
t = this.(Property).getType() or
|
||||
t = this.(Callable).getReturnType() or
|
||||
t = this.(DelegateType).getReturnType()
|
||||
|
|
||||
child = t.getAChild*() and
|
||||
(
|
||||
child instanceof PointerType
|
||||
or
|
||||
child instanceof FunctionPointerType
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/** Holds if this declaration is `async`. */
|
||||
|
||||
@@ -132,11 +132,11 @@ abstract private class GeneratedType extends Type, GeneratedElement {
|
||||
else (
|
||||
not this instanceof DelegateType and
|
||||
result =
|
||||
this.stubAttributes() + stubAccessibility(this) + this.stubAbstractModifier() +
|
||||
this.stubStaticModifier() + this.stubPartialModifier() + this.stubKeyword() + " " +
|
||||
this.getUndecoratedName() + stubGenericArguments(this) + this.stubBaseTypesString() +
|
||||
stubTypeParametersConstraints(this) + "\n{\n" + this.stubPrivateConstructor() +
|
||||
this.stubMembers(assembly) + "}\n\n"
|
||||
this.stubAttributes() + stubUnsafe(this) + stubAccessibility(this) +
|
||||
this.stubAbstractModifier() + this.stubStaticModifier() + this.stubPartialModifier() +
|
||||
this.stubKeyword() + " " + this.getUndecoratedName() + stubGenericArguments(this) +
|
||||
this.stubBaseTypesString() + stubTypeParametersConstraints(this) + "\n{\n" +
|
||||
this.stubPrivateConstructor() + this.stubMembers(assembly) + "}\n\n"
|
||||
or
|
||||
result =
|
||||
this.stubAttributes() + stubUnsafe(this) + stubAccessibility(this) + this.stubKeyword() +
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -172,6 +172,14 @@ namespace Test
|
||||
static explicit IInterface2<Class11>.operator int(Class11 n) => 0;
|
||||
}
|
||||
|
||||
public unsafe class MyUnsafeClass
|
||||
{
|
||||
public static void M1(delegate*<void> f) => throw null;
|
||||
public static void M2(int*[] x) => throw null;
|
||||
public static char* M3() => throw null;
|
||||
public static void M4(int x) => throw null;
|
||||
}
|
||||
|
||||
public enum Enum1
|
||||
{
|
||||
None1,
|
||||
|
||||
Reference in New Issue
Block a user