Browse Source

Protect against [InternalsVisibleTo] stack overflow and fixed a possible cause for that stack overflow

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
b31e10489f
  1. 22
      ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs
  2. 6
      ICSharpCode.NRefactory/TypeSystem/Implementation/MergedNamespace.cs

22
ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs

@ -18,9 +18,9 @@ @@ -18,9 +18,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using ICSharpCode.NRefactory.Utils;
@ -151,13 +151,19 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -151,13 +151,19 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
if (result != null) {
return result;
} else {
internalsVisibleTo = (
from attr in this.AssemblyAttributes
where attr.AttributeType.Name == "InternalsVisibleToAttribute"
&& attr.AttributeType.Namespace == "System.Runtime.CompilerServices"
&& attr.PositionalArguments.Count == 1
select GetShortName(attr.PositionalArguments.Single().ConstantValue as string)
).ToArray();
using (var busyLock = BusyManager.Enter(this)) {
Debug.Assert(busyLock.Success);
if (!busyLock.Success) {
return new string[0];
}
internalsVisibleTo = (
from attr in this.AssemblyAttributes
where attr.AttributeType.Name == "InternalsVisibleToAttribute"
&& attr.AttributeType.Namespace == "System.Runtime.CompilerServices"
&& attr.PositionalArguments.Count == 1
select GetShortName(attr.PositionalArguments.Single().ConstantValue as string)
).ToArray();
}
return internalsVisibleTo;
}
}

6
ICSharpCode.NRefactory/TypeSystem/Implementation/MergedNamespace.cs

@ -129,9 +129,13 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -129,9 +129,13 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
foreach (var ns in namespaces) {
ITypeDefinition typeDef = ns.GetTypeDefinition(name, typeParameterCount);
if (typeDef != null) {
if (typeDef.IsPublic || (typeDef.IsInternal && typeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly))) {
if (typeDef.IsPublic) {
// Prefer accessible types over non-accessible types.
return typeDef;
// || (typeDef.IsInternal && typeDef.ParentAssembly.InternalsVisibleTo(...))
// We can't call InternalsVisibleTo() here as we don't know the correct 'current' assembly,
// and using the main assembly can cause a stack overflow if there
// are internal assembly attributes.
}
anyTypeDef = typeDef;
}

Loading…
Cancel
Save