-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix VB compiler crashes when decoding attributes #61537
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
Conversation
| Case Else | ||
| diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).GetLocation(), NoLocation.Singleton), Me.AttributeClass) | ||
| diagnostics.Add(ERRID.ERR_BadAttribute1, | ||
| If(nodeOpt IsNot Nothing, If(nodeOpt.ArgumentList IsNot Nothing AndAlso nodeOpt.ArgumentList.Arguments.Count > 0, nodeOpt.ArgumentList.Arguments(0).GetLocation(), nodeOpt.GetLocation()), NoLocation.Singleton), |
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 these still use the helper, even if they only care about the location?
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.
@333fred Do I need to share the helper among classes too? e.g, make it publicly available from AttributeData
| Dim argSyntaxLocation As Location = If(arguments.AttributeSyntaxOpt IsNot Nothing, | ||
| arguments.AttributeSyntaxOpt.ArgumentList.Arguments(1).GetLocation(), | ||
| NoLocation.Singleton) |
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.
I wasn't able to write a test that makes a crash here, so I didn't make a change.
In case someone was able to, let me know.
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.
I believe there can be other crashes. Here are code paths I didn't review:
| DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.ERR_BadAttribute1, arguments.AttributeSyntaxOpt.ArgumentList.Arguments(0).GetLocation(), attrData.AttributeClass) |
| diagnostics.Add(ERRID.ERR_BadAttribute1, arguments.AttributeSyntaxOpt.ArgumentList.Arguments(0).GetLocation(), attrData.AttributeClass) |
roslyn/src/Compilers/VisualBasic/Portable/Symbols/Source/SourceAssemblySymbol.vb
Line 1136 in 9c4920a
| diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(i).GetLocation(), NoLocation.Singleton), attrData.AttributeClass) |
#Fixed
|
Do we have similar issues with C# compiler? At least we probably should add similar tests. |
| @@ -3763,15 +3821,86 @@ end class | |||
|
|
|||
| Dim comp = CompilationUtils.CreateCompilationWithMscorlib40AndVBRuntime(source) | |||
| comp.VerifyDiagnostics(Diagnostic(ERRID.ERR_OmittedArgument2, "FileIOPermission").WithArguments("action", "Public Overloads Sub New(action As System.Security.Permissions.SecurityAction)"), | |||
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.
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.
I used it for new tests, but makes sense to use in this modified existing test too. Will do.
| @@ -3812,12 +3941,12 @@ end class | |||
|
|
|||
| Dim comp = CompilationUtils.CreateCompilationWithMscorlib40AndVBRuntimeAndReferences(source) | |||
| comp.VerifyDiagnostics( | |||
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.
I think C# doesn't have the bug, but I'll double check and add tests. |
|
|
||
| Dim comp = CompilationUtils.CreateCompilationWithMscorlib40AndVBRuntime(source) | ||
| comp.AssertTheseDiagnostics(<errors><![CDATA[ | ||
| BC40000: 'RequestMinimum' is obsolete: 'Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.'. |
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.
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).GetLocation(), NoLocation.Singleton), | ||
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).ToString(), "")) | ||
| ' BC31215: SecurityAction value '{0}' is invalid for PrincipalPermission attribute | ||
| Dim valueLocation = GetArgumentAndLocation(nodeOpt, securityAction) |
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.
| Return GetArgumentAndLocation(nodeOpt, 0).Location | ||
| End Function | ||
|
|
||
| Private Shared Function GetArgumentAndLocation(nodeOpt As AttributeSyntax, value As Integer) As (Argument As String, Location As Location) |
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.
| Return GetArgumentAndLocation(nodeOpt, 0).Location | ||
| End Function | ||
|
|
||
| Private Shared Function GetArgumentAndLocation(nodeOpt As AttributeSyntax, value As Integer) As (Argument As String, Location As Location) |
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.
| Return Nothing | ||
| End Function | ||
|
|
||
| Private Shared Function GetLocationForAttributeDiagnostic(nodeOpt As AttributeSyntax) As Location |
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.
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).GetLocation(), NoLocation.Singleton), | ||
| If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(0).ToString(), "")) | ||
| ' BC31215: SecurityAction value '{0}' is invalid for PrincipalPermission attribute | ||
| Dim valueLocation = GetArgumentAndLocation(nodeOpt, securityAction) |
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.
| Else | ||
| location = NoLocation.Singleton | ||
| End If | ||
| diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, location, NoLocation.Singleton), attrData.AttributeClass) |
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.
|
Done with review pass (commit 3) |
|
It looks like there are already C# tests: roslyn/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_Security.cs Lines 1656 to 1707 in d46613c
|
Do they cover all the attributes that we added tests for in this PR for VB? If not, let's open an issue to follow up with tests for C#, listing specific new VB unit-tests. I( do not want to hold this PR because of that. |
AlekseyTs
left a comment
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.
LGTM (commit 5)
|
@333fred, @dotnet/roslyn-compiler For the second review on a community PR. |
They all share the same code path, but I agree the tests are good to have. I opened #61794. |
|
@dotnet/roslyn-compiler For the second review on a community PR. |
1 similar comment
|
@dotnet/roslyn-compiler For the second review on a community PR. |
| End If | ||
| Else | ||
| location = NoLocation.Singleton | ||
| End If |
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.
Is this the same code used in other Source*Symbol methods? If so, consider extracting a helper method.
| <![CDATA[ | ||
| Imports System.Runtime.InteropServices | ||
|
|
||
| <Assembly: TypeLibVersionAttribute(1, -1)> ' Not valid. major is negative. |
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.
AlekseyTs
left a comment
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.
LGTM (commit 7)
|
@Youssef1313 Thanks for the contribution |
Fixes #61492