Skip to content

Commit a247a8b

Browse files
committed
Merge branch 'main' into mathiasvp/replace-ast-with-ir-use-usedataflow
2 parents e68bb53 + 29ee1bd commit a247a8b

File tree

262 files changed

+11058
-9730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+11058
-9730
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
int write_default_config_bad() {
1+
void write_default_config_bad() {
22
// BAD - this is world-writable so any user can overwrite the config
3-
FILE* out = creat(OUTFILE, 0666);
4-
fprintf(out, DEFAULT_CONFIG);
3+
int out = creat(OUTFILE, 0666);
4+
dprintf(out, DEFAULT_CONFIG);
55
}
66

7-
int write_default_config_good() {
7+
void write_default_config_good() {
88
// GOOD - this allows only the current user to modify the file
9-
FILE* out = creat(OUTFILE, S_IWUSR | S_IRUSR);
10-
fprintf(out, DEFAULT_CONFIG);
9+
int out = creat(OUTFILE, S_IWUSR | S_IRUSR);
10+
dprintf(out, DEFAULT_CONFIG);
1111
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* 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.

csharp/ql/lib/semmle/code/csharp/Member.qll

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,21 @@ class Modifiable extends Declaration, @modifiable {
9898

9999
/** Holds if this declaration is `unsafe`. */
100100
predicate isUnsafe() {
101-
this.hasModifier("unsafe") or
102-
this.(Parameterizable).getAParameter().getType() instanceof PointerType or
103-
this.(Property).getType() instanceof PointerType or
104-
this.(Callable).getReturnType() instanceof PointerType
101+
this.hasModifier("unsafe")
102+
or
103+
exists(Type t, Type child |
104+
t = this.(Parameterizable).getAParameter().getType() or
105+
t = this.(Property).getType() or
106+
t = this.(Callable).getReturnType() or
107+
t = this.(DelegateType).getReturnType()
108+
|
109+
child = t.getAChild*() and
110+
(
111+
child instanceof PointerType
112+
or
113+
child instanceof FunctionPointerType
114+
)
115+
)
105116
}
106117

107118
/** Holds if this declaration is `async`. */

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ abstract private class GeneratedType extends Type, GeneratedElement {
132132
else (
133133
not this instanceof DelegateType and
134134
result =
135-
this.stubAttributes() + stubAccessibility(this) + this.stubAbstractModifier() +
136-
this.stubStaticModifier() + this.stubPartialModifier() + this.stubKeyword() + " " +
137-
this.getUndecoratedName() + stubGenericArguments(this) + this.stubBaseTypesString() +
138-
stubTypeParametersConstraints(this) + "\n{\n" + this.stubPrivateConstructor() +
139-
this.stubMembers(assembly) + "}\n\n"
135+
this.stubAttributes() + stubUnsafe(this) + stubAccessibility(this) +
136+
this.stubAbstractModifier() + this.stubStaticModifier() + this.stubPartialModifier() +
137+
this.stubKeyword() + " " + this.getUndecoratedName() + stubGenericArguments(this) +
138+
this.stubBaseTypesString() + stubTypeParametersConstraints(this) + "\n{\n" +
139+
this.stubPrivateConstructor() + this.stubMembers(assembly) + "}\n\n"
140140
or
141141
result =
142142
this.stubAttributes() + stubUnsafe(this) + stubAccessibility(this) + this.stubKeyword() +

csharp/ql/test/library-tests/dataflow/library/FlowSummaries.expected

Lines changed: 941 additions & 39 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/dataflow/library/FlowSummariesFiltered.expected

Lines changed: 63 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| // This file contains auto-generated code.\n// Generated from `Test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null`.\n\nnamespace A1\n{\npublic class C1\n{\n}\n\n}\nnamespace A2\n{\nnamespace B2\n{\npublic class C2\n{\n}\n\n}\n}\nnamespace A3\n{\npublic class C3\n{\n}\n\n}\nnamespace A4\n{\npublic class C4\n{\n}\n\nnamespace B4\n{\npublic class D4\n{\n}\n\n}\n}\nnamespace Test\n{\npublic class Class1\n{\npublic class Class11 : Test.Class1.Interface1, Test.Class1.Interface2\n{\n int Test.Class1.Interface2.this[int i] { get => throw null; }\n public void Method1() => throw null;\n void Test.Class1.Interface2.Method2() => throw null;\n}\n\n\npublic class Class12 : Test.Class1.Class11\n{\n}\n\n\npublic abstract class Class13\n{\n protected internal virtual void M() => throw null;\n public virtual void M1<T>() where T: Test.Class1.Class13 => throw null;\n public abstract void M2();\n}\n\n\npublic abstract class Class14 : Test.Class1.Class13\n{\n protected internal override void M() => throw null;\n public override void M1<T>() => throw null;\n public abstract override void M2();\n}\n\n\npublic delegate void Delegate1<T>(T i, int j);\n\n\npublic class GenericType<T>\n{\npublic class X\n{\n}\n\n\n}\n\n\npublic interface Interface1\n{\n void Method1();\n}\n\n\nprotected internal interface Interface2\n{\n int this[int i] { get; }\n void Method2();\n}\n\n\npublic struct Struct1\n{\n public void Method(Test.Class1.Struct1 s = default(Test.Class1.Struct1)) => throw null;\n public int i;\n public static int j = default;\n public System.ValueTuple<int> t1;\n public (int,int) t2;\n}\n\n\n public event Test.Class1.Delegate1<int> Event1;\n public Test.Class1.GenericType<int>.X Prop { get => throw null; }\n}\n\npublic class Class10\n{\n unsafe public void M1(delegate* unmanaged<System.IntPtr,void> f) => throw null;\n}\n\npublic class Class11 : Test.IInterface2<Test.Class11>, Test.IInterface3<Test.Class11>\n{\n static Test.Class11 Test.IInterface2<Test.Class11>.operator *(Test.Class11 left, Test.Class11 right) => throw null;\n public static Test.Class11 operator +(Test.Class11 left, Test.Class11 right) => throw null;\n public static Test.Class11 operator -(Test.Class11 left, Test.Class11 right) => throw null;\n static Test.Class11 Test.IInterface2<Test.Class11>.operator /(Test.Class11 left, Test.Class11 right) => throw null;\n public void M1() => throw null;\n void Test.IInterface2<Test.Class11>.M2() => throw null;\n public static explicit operator System.Int16(Test.Class11 n) => throw null;\n static explicit Test.IInterface2<Test.Class11>.operator int(Test.Class11 n) => throw null;\n}\n\npublic class Class3\n{\n public object Item { get => throw null; set => throw null; }\n [System.Runtime.CompilerServices.IndexerName("MyItem")]\n public object this[string index] { get => throw null; set => throw null; }\n}\n\npublic class Class4\n{\n unsafe public void M(int* p) => throw null;\n}\n\npublic class Class5 : Test.IInterface1\n{\n public void M2() => throw null;\n}\n\npublic class Class6<T> where T: class, Test.IInterface1\n{\n public virtual void M1<T>() where T: class, Test.IInterface1, new() => throw null;\n}\n\npublic class Class7 : Test.Class6<Test.Class5>\n{\n public override void M1<T>() where T: class => throw null;\n}\n\npublic class Class8\n{\n public static int @this = default;\n}\n\npublic class Class9\n{\npublic class Nested : Test.Class9\n{\n}\n\n\n public Test.Class9.Nested NestedInstance { get => throw null; }\n}\n\npublic enum Enum1 : int\n{\n None1 = 0,\n Some11 = 1,\n Some12 = 2,\n}\n\npublic enum Enum2 : int\n{\n None2 = 2,\n Some21 = 1,\n Some22 = 3,\n}\n\npublic enum Enum3 : int\n{\n None3 = 2,\n Some31 = 1,\n Some32 = 0,\n}\n\npublic enum Enum4 : int\n{\n None4 = 2,\n Some41 = 7,\n Some42 = 6,\n}\n\npublic enum EnumLong : long\n{\n None = 10,\n Some = 223372036854775807,\n}\n\npublic interface IInterface1\n{\n void M1() => throw null;\n void M2();\n}\n\npublic interface IInterface2<T> where T: Test.IInterface2<T>\n{\n static abstract T operator *(T left, T right);\n static abstract T operator +(T left, T right);\n static virtual T operator -(T left, T right) => throw null;\n static virtual T operator /(T left, T right) => throw null;\n void M1();\n void M2();\n static abstract explicit operator System.Int16(T n);\n static abstract explicit operator int(T n);\n}\n\npublic interface IInterface3<T> where T: Test.IInterface3<T>\n{\n static abstract T operator +(T left, T right);\n static virtual T operator -(T left, T right) => throw null;\n void M1();\n static abstract explicit operator System.Int16(T n);\n}\n\n}\n\n\n |
1+
| // This file contains auto-generated code.\n// Generated from `Test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null`.\n\nnamespace A1\n{\npublic class C1\n{\n}\n\n}\nnamespace A2\n{\nnamespace B2\n{\npublic class C2\n{\n}\n\n}\n}\nnamespace A3\n{\npublic class C3\n{\n}\n\n}\nnamespace A4\n{\npublic class C4\n{\n}\n\nnamespace B4\n{\npublic class D4\n{\n}\n\n}\n}\nnamespace Test\n{\npublic class Class1\n{\npublic class Class11 : Test.Class1.Interface1, Test.Class1.Interface2\n{\n int Test.Class1.Interface2.this[int i] { get => throw null; }\n public void Method1() => throw null;\n void Test.Class1.Interface2.Method2() => throw null;\n}\n\n\npublic class Class12 : Test.Class1.Class11\n{\n}\n\n\npublic abstract class Class13\n{\n protected internal virtual void M() => throw null;\n public virtual void M1<T>() where T: Test.Class1.Class13 => throw null;\n public abstract void M2();\n}\n\n\npublic abstract class Class14 : Test.Class1.Class13\n{\n protected internal override void M() => throw null;\n public override void M1<T>() => throw null;\n public abstract override void M2();\n}\n\n\npublic delegate void Delegate1<T>(T i, int j);\n\n\npublic class GenericType<T>\n{\npublic class X\n{\n}\n\n\n}\n\n\npublic interface Interface1\n{\n void Method1();\n}\n\n\nprotected internal interface Interface2\n{\n int this[int i] { get; }\n void Method2();\n}\n\n\npublic struct Struct1\n{\n public void Method(Test.Class1.Struct1 s = default(Test.Class1.Struct1)) => throw null;\n public int i;\n public static int j = default;\n public System.ValueTuple<int> t1;\n public (int,int) t2;\n}\n\n\n public event Test.Class1.Delegate1<int> Event1;\n public Test.Class1.GenericType<int>.X Prop { get => throw null; }\n}\n\npublic class Class10\n{\n unsafe public void M1(delegate* unmanaged<System.IntPtr,void> f) => throw null;\n}\n\npublic class Class11 : Test.IInterface2<Test.Class11>, Test.IInterface3<Test.Class11>\n{\n static Test.Class11 Test.IInterface2<Test.Class11>.operator *(Test.Class11 left, Test.Class11 right) => throw null;\n public static Test.Class11 operator +(Test.Class11 left, Test.Class11 right) => throw null;\n public static Test.Class11 operator -(Test.Class11 left, Test.Class11 right) => throw null;\n static Test.Class11 Test.IInterface2<Test.Class11>.operator /(Test.Class11 left, Test.Class11 right) => throw null;\n public void M1() => throw null;\n void Test.IInterface2<Test.Class11>.M2() => throw null;\n public static explicit operator System.Int16(Test.Class11 n) => throw null;\n static explicit Test.IInterface2<Test.Class11>.operator int(Test.Class11 n) => throw null;\n}\n\npublic class Class3\n{\n public object Item { get => throw null; set => throw null; }\n [System.Runtime.CompilerServices.IndexerName("MyItem")]\n public object this[string index] { get => throw null; set => throw null; }\n}\n\npublic class Class4\n{\n unsafe public void M(int* p) => throw null;\n}\n\npublic class Class5 : Test.IInterface1\n{\n public void M2() => throw null;\n}\n\npublic class Class6<T> where T: class, Test.IInterface1\n{\n public virtual void M1<T>() where T: class, Test.IInterface1, new() => throw null;\n}\n\npublic class Class7 : Test.Class6<Test.Class5>\n{\n public override void M1<T>() where T: class => throw null;\n}\n\npublic class Class8\n{\n public static int @this = default;\n}\n\npublic class Class9\n{\npublic class Nested : Test.Class9\n{\n}\n\n\n public Test.Class9.Nested NestedInstance { get => throw null; }\n}\n\npublic enum Enum1 : int\n{\n None1 = 0,\n Some11 = 1,\n Some12 = 2,\n}\n\npublic enum Enum2 : int\n{\n None2 = 2,\n Some21 = 1,\n Some22 = 3,\n}\n\npublic enum Enum3 : int\n{\n None3 = 2,\n Some31 = 1,\n Some32 = 0,\n}\n\npublic enum Enum4 : int\n{\n None4 = 2,\n Some41 = 7,\n Some42 = 6,\n}\n\npublic enum EnumLong : long\n{\n None = 10,\n Some = 223372036854775807,\n}\n\npublic interface IInterface1\n{\n void M1() => throw null;\n void M2();\n}\n\npublic interface IInterface2<T> where T: Test.IInterface2<T>\n{\n static abstract T operator *(T left, T right);\n static abstract T operator +(T left, T right);\n static virtual T operator -(T left, T right) => throw null;\n static virtual T operator /(T left, T right) => throw null;\n void M1();\n void M2();\n static abstract explicit operator System.Int16(T n);\n static abstract explicit operator int(T n);\n}\n\npublic interface IInterface3<T> where T: Test.IInterface3<T>\n{\n static abstract T operator +(T left, T right);\n static virtual T operator -(T left, T right) => throw null;\n void M1();\n static abstract explicit operator System.Int16(T n);\n}\n\nunsafe public class MyUnsafeClass\n{\n unsafe public static void M1(delegate* <void> f) => throw null;\n unsafe public static void M2(int*[] x) => throw null;\n unsafe public static System.Char* M3() => throw null;\n public static void M4(int x) => throw null;\n}\n\n}\n\n\n |

csharp/ql/test/query-tests/Stubs/All/Test.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ public class Class11 : IInterface2<Class11>, IInterface3<Class11>
172172
static explicit IInterface2<Class11>.operator int(Class11 n) => 0;
173173
}
174174

175+
public unsafe class MyUnsafeClass
176+
{
177+
public static void M1(delegate*<void> f) => throw null;
178+
public static void M2(int*[] x) => throw null;
179+
public static char* M3() => throw null;
180+
public static void M4(int x) => throw null;
181+
}
182+
175183
public enum Enum1
176184
{
177185
None1,

csharp/ql/test/resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.Antiforgery.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// This file contains auto-generated code.
2+
// Generated from `Microsoft.AspNetCore.Antiforgery, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
23

34
namespace Microsoft
45
{
56
namespace AspNetCore
67
{
78
namespace Antiforgery
89
{
9-
// Generated from `Microsoft.AspNetCore.Antiforgery.AntiforgeryOptions` in `Microsoft.AspNetCore.Antiforgery, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`
1010
public class AntiforgeryOptions
1111
{
1212
public AntiforgeryOptions() => throw null;
@@ -17,7 +17,6 @@ public class AntiforgeryOptions
1717
public bool SuppressXFrameOptionsHeader { get => throw null; set => throw null; }
1818
}
1919

20-
// Generated from `Microsoft.AspNetCore.Antiforgery.AntiforgeryTokenSet` in `Microsoft.AspNetCore.Antiforgery, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`
2120
public class AntiforgeryTokenSet
2221
{
2322
public AntiforgeryTokenSet(string requestToken, string cookieToken, string formFieldName, string headerName) => throw null;
@@ -27,14 +26,12 @@ public class AntiforgeryTokenSet
2726
public string RequestToken { get => throw null; }
2827
}
2928

30-
// Generated from `Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException` in `Microsoft.AspNetCore.Antiforgery, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`
3129
public class AntiforgeryValidationException : System.Exception
3230
{
3331
public AntiforgeryValidationException(string message) => throw null;
3432
public AntiforgeryValidationException(string message, System.Exception innerException) => throw null;
3533
}
3634

37-
// Generated from `Microsoft.AspNetCore.Antiforgery.IAntiforgery` in `Microsoft.AspNetCore.Antiforgery, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`
3835
public interface IAntiforgery
3936
{
4037
Microsoft.AspNetCore.Antiforgery.AntiforgeryTokenSet GetAndStoreTokens(Microsoft.AspNetCore.Http.HttpContext httpContext);
@@ -44,7 +41,6 @@ public interface IAntiforgery
4441
System.Threading.Tasks.Task ValidateRequestAsync(Microsoft.AspNetCore.Http.HttpContext httpContext);
4542
}
4643

47-
// Generated from `Microsoft.AspNetCore.Antiforgery.IAntiforgeryAdditionalDataProvider` in `Microsoft.AspNetCore.Antiforgery, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`
4844
public interface IAntiforgeryAdditionalDataProvider
4945
{
5046
string GetAdditionalData(Microsoft.AspNetCore.Http.HttpContext context);
@@ -57,7 +53,6 @@ namespace Extensions
5753
{
5854
namespace DependencyInjection
5955
{
60-
// Generated from `Microsoft.Extensions.DependencyInjection.AntiforgeryServiceCollectionExtensions` in `Microsoft.AspNetCore.Antiforgery, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`
6156
public static class AntiforgeryServiceCollectionExtensions
6257
{
6358
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAntiforgery(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) => throw null;

0 commit comments

Comments
 (0)