diff options
author | Andrés G. Aragoneses <knocte@gmail.com> | 2009-08-08 00:05:52 +0400 |
---|---|---|
committer | Andrés G. Aragoneses <knocte@gmail.com> | 2009-08-08 00:05:52 +0400 |
commit | 2dd5ea989d2b802f737dcea546247ff2f3293f55 (patch) | |
tree | 45b032bddd9b84bc0b199631f2b9d3d90365bb1e | |
parent | 0e57ff8832e0480dd28d7d6bd49372d005f55068 (diff) |
* tuner/Mono.Tuner/InjectSecurityAttributes.cs: Make an enum
protected.
* tuner/Mono.Tuner/MoonlightA11yProcessor.cs: Prevent Type*Exceptions
because of badly placed SC attrib on methods.
* tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Typo in
comment.
svn path=/trunk/mcs/; revision=139589
-rw-r--r-- | mcs/tools/tuner/ChangeLog | 12 | ||||
-rw-r--r-- | mcs/tools/tuner/Mono.Tuner/InjectSecurityAttributes.cs | 4 | ||||
-rw-r--r-- | mcs/tools/tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs | 2 | ||||
-rw-r--r-- | mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs | 62 |
4 files changed, 74 insertions, 6 deletions
diff --git a/mcs/tools/tuner/ChangeLog b/mcs/tools/tuner/ChangeLog index 8b84f3cc604..feada9de0cb 100644 --- a/mcs/tools/tuner/ChangeLog +++ b/mcs/tools/tuner/ChangeLog @@ -1,3 +1,15 @@ +2009-08-07 Andrés G. Aragoneses <aaragoneses@novell.com> + + * Mono.Tuner/InjectSecurityAttributes.cs: Make an enum + protected. + + * Mono.Tuner/MoonlightA11yProcessor.cs: Prevent + Type*Exceptions because of badly placed SC attrib on + methods. + + * Mono.Tuner/MoonlightA11yDescriptorGenerator.cs: Typo in + comment. + 2009-07-02 Jb Evain <jbevain@novell.com> * Makefile: fix cecil's location. diff --git a/mcs/tools/tuner/Mono.Tuner/InjectSecurityAttributes.cs b/mcs/tools/tuner/Mono.Tuner/InjectSecurityAttributes.cs index 215d450a341..0d4bac44e1e 100644 --- a/mcs/tools/tuner/Mono.Tuner/InjectSecurityAttributes.cs +++ b/mcs/tools/tuner/Mono.Tuner/InjectSecurityAttributes.cs @@ -45,7 +45,7 @@ namespace Mono.Tuner { Method, } - enum AttributeType { + protected enum AttributeType { Critical, SafeCritical, } @@ -242,7 +242,7 @@ namespace Mono.Tuner { } } - static bool HasSecurityAttribute (ICustomAttributeProvider provider, AttributeType type) + protected static bool HasSecurityAttribute (ICustomAttributeProvider provider, AttributeType type) { if (!provider.HasCustomAttributes) return false; diff --git a/mcs/tools/tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs b/mcs/tools/tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs index c0f92a91d4b..e50125cc932 100644 --- a/mcs/tools/tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs +++ b/mcs/tools/tuner/Mono.Tuner/MoonlightA11yDescriptorGenerator.cs @@ -112,7 +112,7 @@ namespace Mono.Tuner { return @params; } - Hashtable /*Dictionary<TypeDefinition,List<IAnnotationProvider>>*/ ScanAssembly (AssemblyDefinition assembly) + Hashtable /*Dictionary<TypeDefinition,List<IAnnotationProvider>*/ ScanAssembly (AssemblyDefinition assembly) { if (Annotations.GetAction (assembly) != AssemblyAction.Link) return null; diff --git a/mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs b/mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs index d01a9dc965a..4904671a4f0 100644 --- a/mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs +++ b/mcs/tools/tuner/Mono.Tuner/MoonlightA11yProcessor.cs @@ -87,10 +87,66 @@ namespace Mono.Tuner { AddCriticalAttribute (ctor); if (type.HasMethods) - foreach (MethodDefinition method in type.Methods) - AddCriticalAttribute (method); + foreach (MethodDefinition method in type.Methods) { + MethodDefinition parent = GetOverridenMethod (type, method); + //to prevent Type*Exceptions because of having SC attribs in overriden methods of non-SC base methods + if (parent == null || HasSecurityAttribute (parent, AttributeType.Critical)) + AddCriticalAttribute (method); + } + } } - + +// bool HasSecurityAttribute (ICustomAttributeProvider provider) +// { +// CustomAttributeCollection attributes = provider.CustomAttributes; +// for (int i = 0; i < attributes.Count; i++) { +// CustomAttribute attribute = attributes [i]; +// if (attribute.Constructor.DeclaringType.FullName == _critical) +// return true; +// } +// return false; +// } + + //note: will not return abstract methods + MethodDefinition GetOverridenMethod (TypeDefinition finalType, MethodDefinition final) + { + Console.WriteLine ("__GetOverridenMethod " + finalType.FullName + ":" + final.ToString ()); + var baseType = finalType.BaseType; + while (baseType != null && baseType.Resolve () != null) { + + foreach (MethodDefinition method in baseType.Resolve ().Methods) { + if (!method.IsVirtual || method.Name != final.Name) + continue; + + //TODO: should we discard them? + if (method.IsAbstract) + continue; + + if (HasSameSignature (method, final)) + return method; + } + baseType = baseType.Resolve().BaseType; + } + return null; + } + + //FIXME: take in account generic params + bool HasSameSignature (MethodDefinition method1, MethodDefinition method2) + { + if (method1.ReturnType.ReturnType.FullName != method2.ReturnType.ReturnType.FullName) + return false; + + if (method1.Parameters.Count != method2.Parameters.Count) + return false; + + for (int i = 0; i < method1.Parameters.Count; i++) { + if (method1.Parameters [i].ParameterType.DeclaringType.FullName != + method2.Parameters [i].ParameterType.DeclaringType.FullName) + return false; + } + + return true; + } } } |