Skip to content

Commit 46bc804

Browse files
authored
Merge pull request #2286 from calumgrant/cs/windows-tests
C#: Make qltests pass on all platforms
2 parents b11a742 + b65ab15 commit 46bc804

File tree

15 files changed

+64
-482
lines changed

15 files changed

+64
-482
lines changed

csharp/ql/src/semmle/code/cil/ConsistencyChecks.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class InvalidReturn extends InstructionViolation {
315315
/**
316316
* A throw instruction that does not have a stack size of 0 after it.
317317
*/
318-
class InvalidThrow extends InstructionViolation {
318+
class InvalidThrow extends InstructionViolation, DisabledCheck {
319319
InvalidThrow() { instruction instanceof Throw and instruction.getStackSizeAfter() != 0 }
320320

321321
override string getMessage() {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
| System.Guid System.Guid.ParseExact(System.String,System.String): 11: throw, 0: ldarg.0 [push: 1, pop: 0]; 1: brtrue.s 5: [push: 0, pop: 1]; 2: ldstr "input" [push: 1, pop: 0]; 3: newobj System.ArgumentNullException..ctor [push: 1, pop: 1]; 4: throw [push: 0, pop: 1]; 5: ldarg.0 [push: 1, pop: 0]; 6: call System.String.op_Implicit [push: 1, pop: 1]; 7: ldarg.1 [push: 1, pop: 0]; 8: brtrue.s 12: [push: 0, pop: 1]; 9: ldstr "format" [push: 1, pop: 0]; 10: newobj System.ArgumentNullException..ctor [push: 1, pop: 1]; 11: throw [push: 0, pop: 1] | Throw has invalid stack size: 1 |
21
| System.Runtime.CompilerServices.AsyncTaskMethodBuilder.DebugFinalizableAsyncStateMachineBox.Finalize | Overridden method from System.Object is not in a base type |
3-
| System.Threading.CancellationTokenRegistration System.Threading.CancellationToken.Register(System.Action): 8: throw, 0: ldarg.0 [push: 1, pop: 0]; 1: ldsfld s_actionToActionObjShunt [push: 1, pop: 0]; 2: ldarg.1 [push: 1, pop: 0]; 3: dup [push: 2, pop: 1]; 4: brtrue.s 9: [push: 0, pop: 1]; 5: pop [push: 0, pop: 1]; 6: ldstr "callback" [push: 1, pop: 0]; 7: newobj System.ArgumentNullException..ctor [push: 1, pop: 1]; 8: throw [push: 0, pop: 1] | Throw has invalid stack size: 2 |
4-
| System.Threading.CancellationTokenRegistration System.Threading.CancellationToken.Register(System.Action,System.Boolean): 8: throw, 0: ldarg.0 [push: 1, pop: 0]; 1: ldsfld s_actionToActionObjShunt [push: 1, pop: 0]; 2: ldarg.1 [push: 1, pop: 0]; 3: dup [push: 2, pop: 1]; 4: brtrue.s 9: [push: 0, pop: 1]; 5: pop [push: 0, pop: 1]; 6: ldstr "callback" [push: 1, pop: 0]; 7: newobj System.ArgumentNullException..ctor [push: 1, pop: 1]; 8: throw [push: 0, pop: 1] | Throw has invalid stack size: 2 |
5-
| System.Void System.Guid..ctor(System.Byte[]): 7: throw, 0: ldarg.0 [push: 1, pop: 0]; 1: ldarg.1 [push: 1, pop: 0]; 2: dup [push: 2, pop: 1]; 3: brtrue.s 8: [push: 0, pop: 1]; 4: pop [push: 0, pop: 1]; 5: ldstr "b" [push: 1, pop: 0]; 6: newobj System.ArgumentNullException..ctor [push: 1, pop: 1]; 7: throw [push: 0, pop: 1] | Throw has invalid stack size: 1 |
6-
| System.Void System.TermInfo.Database..ctor(System.String,System.Byte[]): 33: throw, 0: ldarg.0 [push: 1, pop: 0]; 1: call System.Object..ctor [push: 0, pop: 1]; 2: ldarg.0 [push: 1, pop: 0]; 3: ldarg.1 [push: 1, pop: 0]; 4: stfld _term [push: 0, pop: 2]; 5: ldarg.0 [push: 1, pop: 0]; 6: ldarg.2 [push: 1, pop: 0]; 7: stfld _data [push: 0, pop: 2]; 8: ldarg.2 [push: 1, pop: 0]; 9: ldc.i4.0 [push: 1, pop: 0]; 10: call System.TermInfo.Database.ReadInt16 [push: 1, pop: 2]; 11: stloc.0 L0 [push: 0, pop: 1]; 12: ldarg.0 [push: 1, pop: 0]; 13: ldloc.0 [push: 1, pop: 0]; 14: ldc.i4 72224 [push: 1, pop: 0]; 15: beq.s 36: [push: 0, pop: 2]; 16: ldloc.0 [push: 1, pop: 0]; 17: ldc.i4 138784 [push: 1, pop: 0]; 18: beq.s 34: [push: 0, pop: 2]; 19: call System.SR.get_IO_TermInfoInvalidMagicNumber [push: 1, pop: 0]; 20: ldc.i4.1 [push: 1, pop: 0]; 21: newarr System.String [push: 1, pop: 1]; 22: dup [push: 2, pop: 1]; 23: ldc.i4.0 [push: 1, pop: 0]; 24: ldstr "O" [push: 1, pop: 0]; 25: ldloc.0 [push: 1, pop: 0]; 26: ldc.i4.8 [push: 1, pop: 0]; 27: call System.Convert.ToString [push: 1, pop: 2]; 28: call System.String.Concat [push: 1, pop: 2]; 29: stelem.ref [push: 0, pop: 3]; 30: call System.String.Concat [push: 1, pop: 1]; 31: call System.SR.Format [push: 1, pop: 2]; 32: newobj System.InvalidOperationException..ctor [push: 1, pop: 1]; 33: throw [push: 0, pop: 1] | Throw has invalid stack size: 1 |

csharp/ql/test/library-tests/cil/dataflow/CallableReturns.expected

-16
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@ alwaysNull
99
| System.Object System.Collections.EmptyReadOnlyDictionaryInternal.get_Item(System.Object) | 0: ldarg.1, 1: brtrue.s 6:, 2: ldstr "key", 3: call System.SR.get_ArgumentNull_Key, 4: newobj System.ArgumentNullException..ctor, 5: throw, 6: ldnull, 7: ret |
1010
alwaysNonNull
1111
| System.ArgumentException System.ThrowHelper.GetAddingDuplicateWithKeyArgumentException(System.Object) |
12-
| System.ArgumentException System.ThrowHelper.GetArgumentException(System.ExceptionResource) |
13-
| System.ArgumentException System.ThrowHelper.GetArgumentException(System.ExceptionResource,System.ExceptionArgument) |
1412
| System.ArgumentException System.ThrowHelper.GetWrongKeyTypeArgumentException(System.Object,System.Type) |
1513
| System.ArgumentException System.ThrowHelper.GetWrongValueTypeArgumentException(System.Object,System.Type) |
1614
| System.ArgumentNullException System.ThrowHelper.GetArgumentNullException(System.ExceptionArgument) |
17-
| System.ArgumentOutOfRangeException System.ThrowHelper.GetArgumentOutOfRangeException(System.ExceptionArgument,System.ExceptionResource) |
18-
| System.ArgumentOutOfRangeException System.ThrowHelper.GetArgumentOutOfRangeException(System.ExceptionArgument,System.Int32,System.ExceptionResource) |
1915
| System.Collections.Generic.KeyNotFoundException System.ThrowHelper.GetKeyNotFoundException(System.Object) |
2016
| System.Exception System.ThrowHelper.GetArraySegmentCtorValidationFailedException(System.Array,System.Int32,System.Int32) |
21-
| System.InvalidOperationException System.ThrowHelper.GetInvalidOperationException(System.ExceptionResource) |
2217
| System.InvalidOperationException System.ThrowHelper.GetInvalidOperationException_EnumCurrent(System.Int32) |
2318
| System.Object Dataflow.NonNullMethods.ReturnsNonNull2() |
2419
| System.Object Dataflow.NonNullMethods.ReturnsNonNull() |
@@ -41,25 +36,18 @@ alwaysThrows
4136
| System.Object System.ValueTuple.get_Item(System.Int32) | System.IndexOutOfRangeException | 0: newobj System.IndexOutOfRangeException..ctor, 1: throw |
4237
| System.Void System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException`1(!0) | System.ArgumentException | 0: ldarg.0, 1: box, 2: call System.ThrowHelper.GetAddingDuplicateWithKeyArgumentException, 3: throw |
4338
| System.Void System.ThrowHelper.ThrowAggregateException(System.Collections.Generic.List<System.Exception>) | System.AggregateException | 0: ldarg.0, 1: newobj System.AggregateException..ctor, 2: throw |
44-
| System.Void System.ThrowHelper.ThrowArgumentException(System.ExceptionResource) | System.ArgumentException | 0: ldarg.0, 1: call System.ThrowHelper.GetArgumentException, 2: throw |
45-
| System.Void System.ThrowHelper.ThrowArgumentException(System.ExceptionResource,System.ExceptionArgument) | System.ArgumentException | 0: ldarg.0, 1: ldarg.1, 2: call System.ThrowHelper.GetArgumentException, 3: throw |
4639
| System.Void System.ThrowHelper.ThrowArgumentException_Argument_InvalidArrayType() | System.ArgumentException | 0: ldc.i4.s 31, 1: call System.ThrowHelper.GetArgumentException, 2: throw |
4740
| System.Void System.ThrowHelper.ThrowArgumentException_DestinationTooShort() | System.ArgumentException | 0: call System.SR.get_Argument_DestinationTooShort, 1: newobj System.ArgumentException..ctor, 2: throw |
4841
| System.Void System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch() | System.ArgumentException | 0: call System.SR.get_Argument_OverlapAlignmentMismatch, 1: newobj System.ArgumentException..ctor, 2: throw |
4942
| System.Void System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument) | System.ArgumentNullException | 0: ldarg.0, 1: call System.ThrowHelper.GetArgumentNullException, 2: throw |
50-
| System.Void System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument,System.ExceptionResource) | System.ArgumentNullException | 0: ldarg.0, 1: call System.ThrowHelper.GetArgumentName, 2: ldarg.1, 3: call System.ThrowHelper.GetResourceString, 4: newobj System.ArgumentNullException..ctor, 5: throw |
5143
| System.Void System.ThrowHelper.ThrowArgumentOutOfRangeException() | System.ArgumentOutOfRangeException | 0: newobj System.ArgumentOutOfRangeException..ctor, 1: throw |
5244
| System.Void System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument) | System.ArgumentOutOfRangeException | 0: ldarg.0, 1: call System.ThrowHelper.GetArgumentName, 2: newobj System.ArgumentOutOfRangeException..ctor, 3: throw |
53-
| System.Void System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument,System.ExceptionResource) | System.ArgumentOutOfRangeException | 0: ldarg.0, 1: ldarg.1, 2: call System.ThrowHelper.GetArgumentOutOfRangeException, 3: throw |
54-
| System.Void System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument,System.Int32,System.ExceptionResource) | System.ArgumentOutOfRangeException | 0: ldarg.0, 1: ldarg.1, 2: ldarg.2, 3: call System.ThrowHelper.GetArgumentOutOfRangeException, 4: throw |
5545
| System.Void System.ThrowHelper.ThrowArgumentOutOfRange_IndexException() | System.ArgumentOutOfRangeException | 0: ldc.i4.s 31, 1: ldc.i4.s 31, 2: call System.ThrowHelper.GetArgumentOutOfRangeException, 3: throw |
5646
| System.Void System.ThrowHelper.ThrowArraySegmentCtorValidationFailedExceptions(System.Array,System.Int32,System.Int32) | System.Exception | 0: ldarg.0, 1: ldarg.1, 2: ldarg.2, 3: call System.ThrowHelper.GetArraySegmentCtorValidationFailedException, 4: throw |
5747
| System.Void System.ThrowHelper.ThrowArrayTypeMismatchException() | System.ArrayTypeMismatchException | 0: newobj System.ArrayTypeMismatchException..ctor, 1: throw |
5848
| System.Void System.ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count() | System.ArgumentOutOfRangeException | 0: ldc.i4.s 31, 1: ldc.i4.s 31, 2: call System.ThrowHelper.GetArgumentOutOfRangeException, 3: throw |
5949
| System.Void System.ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException() | System.ArgumentOutOfRangeException | 0: ldc.i4.s 31, 1: ldc.i4.4, 2: call System.ThrowHelper.GetArgumentOutOfRangeException, 3: throw |
6050
| System.Void System.ThrowHelper.ThrowIndexOutOfRangeException() | System.IndexOutOfRangeException | 0: newobj System.IndexOutOfRangeException..ctor, 1: throw |
61-
| System.Void System.ThrowHelper.ThrowInvalidOperationException(System.ExceptionResource) | System.InvalidOperationException | 0: ldarg.0, 1: call System.ThrowHelper.GetInvalidOperationException, 2: throw |
62-
| System.Void System.ThrowHelper.ThrowInvalidOperationException(System.ExceptionResource,System.Exception) | System.InvalidOperationException | 0: ldarg.0, 1: call System.ThrowHelper.GetResourceString, 2: ldarg.1, 3: newobj System.InvalidOperationException..ctor, 4: throw |
6351
| System.Void System.ThrowHelper.ThrowInvalidOperationException_ConcurrentOperationsNotSupported() | System.InvalidOperationException | 0: ldc.i4.s 31, 1: call System.ThrowHelper.GetInvalidOperationException, 2: throw |
6452
| System.Void System.ThrowHelper.ThrowInvalidOperationException_EnumCurrent(System.Int32) | System.InvalidOperationException | 0: ldarg.0, 1: call System.ThrowHelper.GetInvalidOperationException_EnumCurrent, 2: throw |
6553
| System.Void System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumEnded() | System.InvalidOperationException | 0: ldc.i4.s 31, 1: call System.ThrowHelper.GetInvalidOperationException, 2: throw |
@@ -71,11 +59,7 @@ alwaysThrows
7159
| System.Void System.ThrowHelper.ThrowKeyNotFoundException`1(!0) | System.Collections.Generic.KeyNotFoundException | 0: ldarg.0, 1: box, 2: call System.ThrowHelper.GetKeyNotFoundException, 3: throw |
7260
| System.Void System.ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum() | System.ArgumentOutOfRangeException | 0: ldc.i4.s 31, 1: ldc.i4.4, 2: call System.ThrowHelper.GetArgumentOutOfRangeException, 3: throw |
7361
| System.Void System.ThrowHelper.ThrowNotSupportedException() | System.NotSupportedException | 0: newobj System.NotSupportedException..ctor, 1: throw |
74-
| System.Void System.ThrowHelper.ThrowNotSupportedException(System.ExceptionResource) | System.NotSupportedException | 0: ldarg.0, 1: call System.ThrowHelper.GetResourceString, 2: newobj System.NotSupportedException..ctor, 3: throw |
75-
| System.Void System.ThrowHelper.ThrowObjectDisposedException(System.ExceptionResource) | System.ObjectDisposedException | 0: ldnull, 1: ldarg.0, 2: call System.ThrowHelper.GetResourceString, 3: newobj System.ObjectDisposedException..ctor, 4: throw |
7662
| System.Void System.ThrowHelper.ThrowOutOfMemoryException() | System.OutOfMemoryException | 0: newobj System.OutOfMemoryException..ctor, 1: throw |
77-
| System.Void System.ThrowHelper.ThrowRankException(System.ExceptionResource) | System.RankException | 0: ldarg.0, 1: call System.ThrowHelper.GetResourceString, 2: newobj System.RankException..ctor, 3: throw |
78-
| System.Void System.ThrowHelper.ThrowSerializationException(System.ExceptionResource) | System.Runtime.Serialization.SerializationException | 0: ldarg.0, 1: call System.ThrowHelper.GetResourceString, 2: newobj System.Runtime.Serialization.SerializationException..ctor, 3: throw |
7963
| System.Void System.ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index() | System.ArgumentOutOfRangeException | 0: ldc.i4.s 31, 1: ldc.i4.s 31, 2: call System.ThrowHelper.GetArgumentOutOfRangeException, 3: throw |
8064
| System.Void System.ThrowHelper.ThrowWrongKeyTypeArgumentException`1(!0,System.Type) | System.ArgumentException | 0: ldarg.0, 1: box, 2: ldarg.1, 3: call System.ThrowHelper.GetWrongKeyTypeArgumentException, 4: throw |
8165
| System.Void System.ThrowHelper.ThrowWrongValueTypeArgumentException`1(!0,System.Type) | System.ArgumentException | 0: ldarg.0, 1: box, 2: ldarg.1, 3: call System.ThrowHelper.GetWrongValueTypeArgumentException, 4: throw |

csharp/ql/test/library-tests/cil/dataflow/CallableReturns.ql

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ predicate relevantMethod(CIL::Method m) {
66
or
77
m.getName() = "get_Item"
88
or
9-
m.getDeclaringType().getName() = "ThrowHelper"
9+
m.getDeclaringType().getName() = "ThrowHelper" and
10+
not m.getParameter(_).getType().getName() = "ExceptionResource"
1011
or
1112
m.getLocation().(CIL::Assembly).getName().matches("DataFlow%")
1213
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
3+
namespace DisposalTests
4+
{
5+
public class MyType : IDisposable
6+
{
7+
public void Dispose()
8+
{
9+
}
10+
}
11+
12+
public class Class1 : IDisposable
13+
{
14+
public void DisposesParameter(IDisposable p1, IDisposable p2)
15+
{
16+
p1.Dispose();
17+
}
18+
19+
public void CapturesDisposable(MyType p1, MyType p2)
20+
{
21+
field1 = p1;
22+
field2 = p2;
23+
}
24+
25+
public void DisposesSelf()
26+
{
27+
Dispose();
28+
}
29+
30+
MyType field1, field2;
31+
32+
public void Dispose()
33+
{
34+
field1.Dispose();
35+
}
36+
37+
public static void Dispose(IDisposable d)
38+
{
39+
d.Dispose();
40+
}
41+
}
42+
}

csharp/ql/test/library-tests/commons/Disposal/Disposal.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public Disposal(IDisposable p1, object p2, System.IO.TextWriter fs)
2121
field1 = p1;
2222
if(p2 is IDisposable d)
2323
d.Dispose();
24-
Console.SetOut(fs);
24+
DisposalTests.Class1.Dispose(fs);
2525
}
2626
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,49 +1 @@
1-
| System.IO.BufferedStream._stream |
2-
| System.IO.Stream.SyncStream._stream |
3-
| System.IO.SyncTextReader._in |
4-
| System.IO.SyncTextWriter._out |
5-
| System.IO.UnmanagedMemoryStreamWrapper._unmanagedStream |
6-
| System.Net.Http.DecompressionHandler.DecompressedContent._originalContent |
7-
| System.Net.Http.DecompressionHandler._innerHandler |
8-
| System.Net.Http.DelegatingHandler._innerHandler |
9-
| System.Net.Http.DelegatingStream._innerStream |
10-
| System.Net.Http.HttpAuthenticatedConnectionHandler._poolManager |
11-
| System.Net.Http.HttpClient._pendingRequestsCts |
12-
| System.Net.Http.HttpConnection.HttpConnectionResponseContent._stream |
13-
| System.Net.Http.HttpConnection._stream |
14-
| System.Net.Http.HttpConnectionHandler._poolManager |
15-
| System.Net.Http.HttpConnectionPool.CachedConnection._connection |
16-
| System.Net.Http.HttpConnectionPool.ConnectionWaiter._cancellationTokenRegistration |
17-
| System.Net.Http.HttpConnectionPoolManager._cleaningTimer |
18-
| System.Net.Http.HttpContent._bufferedContent |
19-
| System.Net.Http.HttpContentStream._connection |
20-
| System.Net.Http.HttpMessageInvoker._handler |
21-
| System.Net.Http.HttpRequestMessage._content |
22-
| System.Net.Http.HttpResponseMessage._content |
23-
| System.Net.Http.NoWriteNoSeekStreamContent._content |
24-
| System.Net.Http.RedirectHandler._initialInnerHandler |
25-
| System.Net.Http.RedirectHandler._redirectInnerHandler |
26-
| System.Net.Http.SocketsHttpHandler._handler |
27-
| System.Net.Http.StreamContent._content |
28-
| System.Net.NTAuthentication._credentialsHandle |
29-
| System.Net.NTAuthentication._securityContext |
30-
| System.Net.Security.SafeDeleteNegoContext._context |
31-
| System.Net.Security.SafeDeleteNegoContext._targetName |
32-
| System.Security.SecureString._buffer |
33-
| System.Threading.CancellationTokenSource.Linked1CancellationTokenSource._reg1 |
34-
| System.Threading.CancellationTokenSource.Linked2CancellationTokenSource._reg1 |
35-
| System.Threading.CancellationTokenSource.Linked2CancellationTokenSource._reg2 |
36-
| System.Threading.CancellationTokenSource._timer |
37-
| System.Threading.ReaderWriterLockSlim._readEvent |
38-
| System.Threading.ReaderWriterLockSlim._upgradeEvent |
39-
| System.Threading.ReaderWriterLockSlim._waitUpgradeEvent |
40-
| System.Threading.ReaderWriterLockSlim._writeEvent |
41-
| System.Xml.Serialization.XmlCountingReader._innerReader |
42-
| System.Xml.XmlAsyncCheckReader._coreReader |
43-
| System.Xml.XmlAsyncCheckWriter._coreWriter |
44-
| System.Xml.XmlAutoDetectWriter._strm |
45-
| System.Xml.XmlAutoDetectWriter._textWriter |
46-
| System.Xml.XmlAutoDetectWriter._wrapped |
47-
| System.Xml.XmlSqlBinaryReader._inStrm |
48-
| System.Xml.XmlTextWriter._textWriter |
49-
| System.Xml.Xsl.Runtime.XmlRawWriterWrapper._wrapped |
1+
| DisposalTests.Class1.field1 |
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import cil
22
import semmle.code.csharp.commons.Disposal
3-
import Whitelist
43

54
from CIL::Field field
65
where
76
mayBeDisposed(field) and
8-
field.getName().charAt(0) = "_" and // Filter the results a little
9-
not whitelistedType(field.getDeclaringType())
7+
field.getDeclaringType().getQualifiedName() = "DisposalTests.Class1"
108
select field.getQualifiedName()

0 commit comments

Comments
 (0)