-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hopefully fixed the bug. #2710
Hopefully fixed the bug. #2710
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArray_CreateEncryptor_Diagnostic() | ||
public void Test_HardcodedInByteArray_CreateEncryptor_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -94,11 +94,11 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
rijn.CreateEncryptor(rgbKey, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(11, 9, 9, 36, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(11, 9, 9, 25, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArray_CreateDecryptor_Diagnostic() | ||
public void Test_HardcodedInByteArray_CreateDecryptor_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -113,11 +113,11 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
rijn.CreateDecryptor(rgbKey, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(11, 9, 9, 36, "ICryptoTransform SymmetricAlgorithm.CreateDecryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(11, 9, 9, 25, "ICryptoTransform SymmetricAlgorithm.CreateDecryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArrayWithVariable_CreateEncryptor_Diagnostic() | ||
public void Test_HardcodedInByteArrayWithVariable_CreateEncryptor_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -133,11 +133,11 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
rijn.CreateEncryptor(rgbKey, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(12, 9, 10, 36, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(12, 9, 10, 25, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArray_KeyProperty_Diagnostic() | ||
public void Test_HardcodedInByteArray_KeyProperty_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -152,11 +152,11 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
rijn.Key = rgbKey; | ||
} | ||
}", | ||
GetCSharpResultAt(11, 9, 9, 36, "byte[] SymmetricAlgorithm.Key", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(11, 9, 9, 25, "byte[] SymmetricAlgorithm.Key", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArray_CreateEncryptorFromDerivedClassOfSymmetricAlgorithm_Diagnostic() | ||
public void Test_HardcodedInByteArray_CreateEncryptorFromDerivedClassOfSymmetricAlgorithm_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -171,11 +171,11 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
aes.CreateEncryptor(rgbKey, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(11, 9, 9, 36, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(11, 9, 9, 25, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArray_CreateEncryptor_Multivalues_Diagnostic() | ||
public void Test_HardcodedInByteArray_CreateEncryptor_Multivalues_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -197,12 +197,12 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
rijn.CreateEncryptor(rgbKey, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(18, 9, 14, 33, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)"), | ||
GetCSharpResultAt(18, 9, 9, 36, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(18, 9, 14, 22, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)"), | ||
GetCSharpResultAt(18, 9, 9, 25, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedInbyteArray_CreateEncryptor_WithoutAssignment_Diagnostic() | ||
public void Test_HardcodedInByteArray_CreateEncryptor_WithoutAssignment_Diagnostic() | ||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
|
@@ -216,7 +216,7 @@ public void TestMethod(byte[] someOtherBytesForIV) | |
rijn.CreateEncryptor(new byte[] {1, 2, 3}, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(10, 9, 10, 41, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
GetCSharpResultAt(10, 9, 10, 30, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
|
@@ -241,7 +241,7 @@ public void TestMethod(byte[] someOtherBytesForIV, byte[] rgbKey) | |
rijn.CreateEncryptor(rgbKey, someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(17, 9, 13, 33, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV, byte[] rgbKey)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV, byte[] rgbKey)")); | ||
GetCSharpResultAt(17, 9, 13, 22, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV, byte[] rgbKey)", "byte[]", "void TestClass.TestMethod(byte[] someOtherBytesForIV, byte[] rgbKey)")); | ||
} | ||
|
||
[Fact] | ||
|
@@ -292,6 +292,26 @@ public void CreateEncryptor(byte[] rgbKey) | |
GetCSharpResultAt(16, 9, 9, 22, "byte[] SymmetricAlgorithm.Key", "void TestClass.CreateEncryptor(byte[] rgbKey)", "byte[] Convert.FromBase64String(string s)", "void TestClass.TestMethod()")); | ||
} | ||
|
||
[Fact] | ||
public void Test_HardcodedIn2DByteArray_CreateEncryptor_Diagnostic() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It'd be good to add a test for a jagged array (like byte[][]) also. Is there a test case that covers the assert from #2708? |
||
{ | ||
VerifyCSharpWithDependencies(@" | ||
using System; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
|
||
class TestClass | ||
{ | ||
public void TestMethod(byte[] someOtherBytesForIV) | ||
{ | ||
byte[,] rgbKey = new byte[,] { { 1, 2, 3 }, { 4, 5, 6 } }; | ||
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create(); | ||
rijn.CreateEncryptor(rgbKey.Cast<byte>().ToArray(), someOtherBytesForIV); | ||
} | ||
}", | ||
GetCSharpResultAt(12, 9, 10, 26, "ICryptoTransform SymmetricAlgorithm.CreateEncryptor(byte[] rgbKey, byte[] rgbIV)", "void TestClass.TestMethod(byte[] someOtherBytesForIV)", "byte[,]", "void TestClass.TestMethod(byte[] someOtherBytesForIV)")); | ||
} | ||
|
||
[Fact] | ||
public void Test_NotHardcoded_CreateEncryptor_NoDiagnostic() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,10 +343,12 @@ public override TaintedDataAbstractValue VisitArrayInitializer(IArrayInitializer | |
result = TaintedDataAbstractValue.MergeTainted(taintedAbstractValues); | ||
} | ||
|
||
if (this.DataFlowAnalysisContext.SourceInfos.IsSourceConstantArrayOfType(operation.Parent.Type as IArrayTypeSymbol) | ||
IArrayCreationOperation arrayCreationOperation = operation.GetAncestor<IArrayCreationOperation>(OperationKind.ArrayCreation); | ||
IArrayTypeSymbol arrayTypeSymbol = arrayCreationOperation.Type as IArrayTypeSymbol; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. I would handle null value return by GetAncestor and also null check before invoking IsSourceConstantArrayOfType (unless that method handles null input). |
||
if (this.DataFlowAnalysisContext.SourceInfos.IsSourceConstantArrayOfType(arrayTypeSymbol) | ||
&& operation.ElementValues.All(s => GetValueContentAbstractValue(s).IsLiteralState)) | ||
{ | ||
TaintedDataAbstractValue taintedDataAbstractValue = TaintedDataAbstractValue.CreateTainted(operation.Parent.Type, operation.Syntax, this.OwningSymbol); | ||
TaintedDataAbstractValue taintedDataAbstractValue = TaintedDataAbstractValue.CreateTainted(arrayTypeSymbol, arrayCreationOperation.Syntax, this.OwningSymbol); | ||
result = result == null ? taintedDataAbstractValue : TaintedDataAbstractValue.MergeTainted(result, taintedDataAbstractValue); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be even more defensive and handle GetAncestor returning null gracefully by using “?.Type”?