Skip to content

Conversation

@Youssef1313
Copy link
Member

Fixes #61492

@Youssef1313 Youssef1313 requested a review from a team as a code owner May 26, 2022 18:28
@ghost ghost added Community The pull request was submitted by a contributor who is not a Microsoft employee. Area-Compilers labels May 26, 2022
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),
Copy link
Member

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?

Copy link
Member Author

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

Comment on lines 387 to 389
Dim argSyntaxLocation As Location = If(arguments.AttributeSyntaxOpt IsNot Nothing,
arguments.AttributeSyntaxOpt.ArgumentList.Arguments(1).GetLocation(),
NoLocation.Singleton)
Copy link
Member Author

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.

Copy link
Member Author

@Youssef1313 Youssef1313 left a 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)

diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, nodeOpt.ArgumentList.Arguments(i).GetLocation(), NoLocation.Singleton), attrData.AttributeClass)

#Fixed

@AlekseyTs
Copy link
Contributor

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)"),
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyDiagnostics

Please use AssertTheseDiagnostics instead. Otherwise, we cannot tell how the error message is going to look like. #Closed

Copy link
Member Author

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(
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VerifyDiagnostics

AssertTheseDiagnostics #Closed

@Youssef1313
Copy link
Member Author

Do we have similar issues with C# compiler? At least we probably should add similar tests.

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.'.
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BC40000

Please get rid of all unrelated diagnostics from the baselines (applies to other added tests too). For example, it should be possible to disable warnings with #Disable Warning directive #Closed

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)
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dim

Please spell out the type. We are not using implicit typing in declarations when the type isn't obvious from the initial value (i.e. not somehow spelled out there). #Closed

Return GetArgumentAndLocation(nodeOpt, 0).Location
End Function

Private Shared Function GetArgumentAndLocation(nodeOpt As AttributeSyntax, value As Integer) As (Argument As String, Location As Location)
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetArgumentAndLocation

GetFirstArgumentDisplayAndLocation? #Closed

Return GetArgumentAndLocation(nodeOpt, 0).Location
End Function

Private Shared Function GetArgumentAndLocation(nodeOpt As AttributeSyntax, value As Integer) As (Argument As String, Location As Location)
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argument

ArgumentDisplay? #Closed

Return Nothing
End Function

Private Shared Function GetLocationForAttributeDiagnostic(nodeOpt As AttributeSyntax) As Location
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetLocationForAttributeDiagnostic

GetFirstArgumentLocation? #Closed

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)
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valueLocation

displayAndLocation? #Closed

Else
location = NoLocation.Singleton
End If
diagnostics.Add(ERRID.ERR_BadAttribute1, If(nodeOpt IsNot Nothing, location, NoLocation.Singleton), attrData.AttributeClass)
Copy link
Contributor

@AlekseyTs AlekseyTs May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If(nodeOpt IsNot Nothing,

Do we still need to keep the conditional? #Closed

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

@Youssef1313
Copy link
Member Author

It looks like there are already C# tests:

[Fact]
[WorkItem(1034429, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1034429")]
public void CrashOnParamsInSecurityAttribute()
{
const string source = @"
using System.Security.Permissions;
class Program
{
[A(SecurityAction.Assert)]
static void Main()
{
}
}
public class A : CodeAccessSecurityAttribute
{
public A(params SecurityAction a)
{
}
}";
CreateCompilationWithMscorlib46(source).GetDiagnostics();
}
[Fact]
[WorkItem(1036339, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1036339")]
public void CrashOnOptionalParameterInSecurityAttribute()
{
const string source = @"
using System.Security.Permissions;
[A]
[A()]
class A : CodeAccessSecurityAttribute
{
public A(SecurityAction a = 0) : base(a)
{
}
}";
CreateCompilationWithMscorlib46(source).VerifyDiagnostics(
// (4,2): error CS7049: Security attribute 'A' has an invalid SecurityAction value '0'
// [A]
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "A").WithArguments("A", "0").WithLocation(4, 2),
// (5,2): error CS7049: Security attribute 'A' has an invalid SecurityAction value '0'
// [A()]
Diagnostic(ErrorCode.ERR_SecurityAttributeInvalidAction, "A()").WithArguments("A", "0").WithLocation(5, 2),
// (6,7): error CS0534: 'A' does not implement inherited abstract member 'SecurityAttribute.CreatePermission()'
// class A : CodeAccessSecurityAttribute
Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "A").WithArguments("A", "System.Security.Permissions.SecurityAttribute.CreatePermission()").WithLocation(6, 7));
}
}
}

@Youssef1313 Youssef1313 requested review from 333fred and AlekseyTs June 7, 2022 08:57
@AlekseyTs
Copy link
Contributor

It looks like there are already C# tests

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.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 5)

@AlekseyTs
Copy link
Contributor

@333fred, @dotnet/roslyn-compiler For the second review on a community PR.

@Youssef1313
Copy link
Member Author

It looks like there are already C# tests

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.

They all share the same code path, but I agree the tests are good to have. I opened #61794.

@AlekseyTs
Copy link
Contributor

@dotnet/roslyn-compiler For the second review on a community PR.

1 similar comment
@AlekseyTs
Copy link
Contributor

@dotnet/roslyn-compiler For the second review on a community PR.

End If
Else
location = NoLocation.Singleton
End If
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major

"minor"?

@Youssef1313 Youssef1313 requested a review from cston June 12, 2022 14:46
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 7)

@AlekseyTs AlekseyTs enabled auto-merge (squash) June 13, 2022 13:46
@AlekseyTs AlekseyTs merged commit 9f883da into dotnet:main Jun 13, 2022
@ghost ghost added this to the Next milestone Jun 13, 2022
@Youssef1313 Youssef1313 deleted the vb-crashes branch June 13, 2022 15:04
@AlekseyTs
Copy link
Contributor

@Youssef1313 Thanks for the contribution

@RikkiGibson RikkiGibson modified the milestones: Next, 17.3 P3 Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VB compiler crashes with NullReferenceException in decoding well-known attributes

5 participants