C#: Sunset the QL based stub generator.

This commit is contained in:
Michael Nebel
2023-10-03 11:12:30 +02:00
parent 319b799f95
commit 4e99266b65
16 changed files with 0 additions and 1531 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
Stubs/AllStubsFromSource.ql

View File

@@ -1,249 +0,0 @@
using System;
namespace Test
{
public class Class1
{
public struct Struct1
{
public ValueTuple<int> t1;
public (int, int) t2;
public int i;
public const int j = 42;
public void Method(Struct1 s = new Struct1()) => throw null;
}
public interface Interface1
{
void Method1();
}
internal protected interface Interface2
{
void Method2();
int this[int i] { get; }
}
private protected interface Interface3
{
void Method3();
}
public class Class11 : Interface1, Interface2, Interface3
{
public Class11(int i) => throw null;
public void Method1() => throw null;
void Interface2.Method2() => throw null;
int Interface2.this[int i] => throw null;
void Interface3.Method3() => throw null;
}
public delegate void Delegate1<T>(T i, int j);
public event Delegate1<int> Event1 { add { } remove { } }
public class Class12 : Class11
{
public Class12(int i, float j) : base(1) => throw null;
}
public class GenericType<T>
{
public class X { }
}
public GenericType<int>.X Prop { get; }
public abstract class Class13
{
protected internal virtual void M() => throw null;
public virtual void M1<T>() where T : Class13 => throw null;
public abstract void M2();
}
public abstract class Class14 : Class13
{
protected internal override void M() => throw null;
public override void M1<T>() => throw null;
public abstract override void M2();
}
}
internal class Class2
{
public void M() => throw null;
}
public class Class3
{
public object Item { get; set; }
[System.Runtime.CompilerServices.IndexerName("MyItem")]
public object this[string index] { get { return null; } set { } }
}
public class Class4
{
unsafe public void M(int* p) => throw null;
}
public interface IInterface1
{
void M1() => throw null;
void M2();
}
public class Class5 : IInterface1
{
public void M2() => throw null;
}
public class Class6<T> where T : class, IInterface1
{
public Class6(int i) => throw null;
public virtual void M1<T>() where T : class, IInterface1, new() => throw null;
}
public class Class7 : Class6<Class5>
{
public Class7(int i) : base(i) => throw null;
public override void M1<T>() where T : class => throw null;
}
public class Class8
{
public const int @this = 10;
}
public class Class9
{
private Class9(int i) => throw null;
public class Nested : Class9
{
internal Nested(int i) : base(i) => throw null;
}
public Class9.Nested NestedInstance { get; } = new Class9.Nested(1);
}
public class Class10
{
unsafe public void M1(delegate* unmanaged<System.IntPtr, void> f) => throw null;
}
public interface IInterface2<T> where T : IInterface2<T>
{
static abstract T operator +(T left, T right);
static virtual T operator -(T left, T right) => throw null;
static abstract T operator *(T left, T right);
static virtual T operator /(T left, T right) => throw null;
static abstract explicit operator short(T n);
static abstract explicit operator int(T n);
void M1();
void M2();
}
public interface IInterface3<T> where T : IInterface3<T>
{
static abstract T operator +(T left, T right);
static virtual T operator -(T left, T right) => throw null;
static abstract explicit operator short(T n);
void M1();
}
public class Class11 : IInterface2<Class11>, IInterface3<Class11>
{
public static Class11 operator +(Class11 left, Class11 right) => throw null;
public static Class11 operator -(Class11 left, Class11 right) => throw null;
static Class11 IInterface2<Class11>.operator *(Class11 left, Class11 right) => throw null;
static Class11 IInterface2<Class11>.operator /(Class11 left, Class11 right) => throw null;
public void M1() => throw null;
void IInterface2<Class11>.M2() => throw null;
public static explicit operator short(Class11 n) => 0;
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,
Some11,
Some12
}
public enum Enum2
{
None2 = 2,
Some21 = 1,
Some22 = 3
}
public enum Enum3
{
Some32,
Some31,
None3
}
public enum Enum4
{
Some41 = 7,
None4 = 2,
Some42 = 6
}
public enum EnumLong : long
{
Some = 223372036854775807,
None = 10
}
}
namespace A1
{
namespace B1
{
}
public class C1 { }
}
namespace A2
{
namespace B2
{
public class C2 { }
}
}
namespace A3
{
public class C3 { }
}
namespace A4
{
namespace B4
{
public class D4 { }
}
public class C4 { }
}

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
Stubs/MinimalStubsFromSource.ql

View File

@@ -1,123 +0,0 @@
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
public class RegexHandler
{
private static readonly string JAVA_CLASS_REGEX = "^(([a-z])+.)+[A-Z]([a-z])+$";
public void ProcessRequest()
{
string userInput = "";
// BAD:
// Artificial regexes
new Regex("^([a-z]+)+$").Match(userInput);
new Regex("^([a-z]*)*$").Replace(userInput, "");
// Known exponential blowup regex for e-mail address validation
// Problematic part is: ([a-zA-Z0-9]+))*
new Regex("^([a-zA-Z0-9])(([\\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$").Match(userInput);
// Known exponential blowup regex for Java class name validation
// Problematic part is: (([a-z])+.)+
new Regex(JAVA_CLASS_REGEX).Match(userInput);
// Static use
Regex.Match(userInput, JAVA_CLASS_REGEX);
// GOOD:
new Regex("^(([a-b]+[c-z]+)+$").Match(userInput);
new Regex("^([a-z]+)+$", RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1)).Match(userInput);
Regex.Match(userInput, JAVA_CLASS_REGEX, RegexOptions.IgnoreCase, TimeSpan.FromSeconds(1));
// Known possible FP.
new Regex("^[a-z0-9]+([_.-][a-z0-9]+)*$").Match(userInput);
}
}
// The only purpose of this class is to make sure the extractor extracts the
// relevant library methods
public class LibraryTypeDataFlow
{
void M()
{
int i;
int.Parse("");
int.TryParse("", out i);
bool b;
bool.Parse("");
bool.TryParse("", out b);
Uri uri = null;
uri.ToString();
StringReader sr = new StringReader("");
string s = new string(new[] { 'a' });
string.Join("", "", "", "");
StringBuilder sb = new StringBuilder("");
Lazy<int> l = new Lazy<int>(() => 42);
IEnumerable ie = null;
ie.GetEnumerator();
ie.AsParallel();
ie.AsQueryable();
IEnumerable<int> ieint = null;
ieint.Select(x => x);
List<int> list = null;
list.Find(x => x > 0);
Stack<int> stack = null;
stack.Peek();
ArrayList al = null;
ArrayList.FixedSize(al);
SortedList sl = null;
sl.GetByIndex(0);
Convert.ToInt32("0");
DataContract dc = null;
s = dc.AString;
KeyValuePair<int, string> kvp = new KeyValuePair<int, string>(0, "");
IEnumerator ienum = null;
object o = ienum.Current;
IEnumerator<int> ienumint = null;
i = ienumint.Current;
var task = new Task(() => { });
Task.WhenAll<int>(null, null);
Task.WhenAny<int>(null, null);
Task.Factory.ContinueWhenAll((Task[])null, (Func<Task[], int>)null);
var task2 = new Task<int>(() => 42);
Task<string>.Factory.ContinueWhenAny<int>(new Task<int>[] { task2 }, t => t.Result.ToString());
Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(""));
Path.Combine("", "");
Path.GetDirectoryName("");
Path.GetExtension("");
Path.GetFileName("");
Path.GetFileNameWithoutExtension("");
Path.GetPathRoot("");
HttpContextBase context = null;
string name = context.Request.QueryString["name"];
}
[DataContract]
public class DataContract
{
[DataMember]
public string AString { get; set; }
}
}

View File

@@ -1 +0,0 @@
semmle-extractor-options: /r:System.Text.RegularExpressions.dll /r:System.Collections.Specialized.dll /r:System.Net.dll /r:System.Web.dll /r:System.Net.HttpListener.dll /r:System.Collections.Specialized.dll /r:System.Private.Uri.dll /r:System.Runtime.Extensions.dll /r:System.Linq.Parallel.dll /r:System.Collections.Concurrent.dll /r:System.Linq.Expressions.dll /r:System.Collections.dll /r:System.Linq.Queryable.dll /r:System.Linq.dll /r:System.Collections.NonGeneric.dll /r:System.ObjectModel.dll /r:System.ComponentModel.TypeConverter.dll /r:System.IO.Compression.dll /r:System.IO.Pipes.dll /r:System.Net.Primitives.dll /r:System.Net.Security.dll /r:System.Security.Cryptography.Primitives.dll /r:System.Text.RegularExpressions.dll ${testdir}/../../../resources/stubs/System.Web.cs /r:System.Runtime.Serialization.Primitives.dll

View File

@@ -1,6 +0,0 @@
namespace Test
{
public class Class1
{
}
}

View File

@@ -1 +0,0 @@
| Test.cs:0:0:0:0 | Test.cs |

View File

@@ -1,5 +0,0 @@
import csharp
from File f
where f.fromSource()
select f

View File

@@ -1,3 +0,0 @@
semmle-extractor-options: --load-sources-from-project:../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj
semmle-extractor-options: /nostdlib
semmle-extractor-options: /noconfig