Skip to content

Commit 034fc7a

Browse files
committed
NH-3807 - Guard System.Security permissions and attributes
1 parent b5f9c1c commit 034fc7a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/NHibernate/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
[assembly: AssemblyProductAttribute("NHibernate")]
1010
[assembly: AssemblyCopyrightAttribute("Licensed under LGPL.")]
1111
[assembly: AssemblyDelaySignAttribute(false)]
12+
#if FEATURE_SECURITY_PERMISSIONS
1213
[assembly: AllowPartiallyTrustedCallersAttribute()]
1314
[assembly: SecurityRulesAttribute(SecurityRuleSet.Level1)]
15+
#endif
1416

src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System.Reflection;
22
using System.Reflection.Emit;
33
using System.Security;
4-
using System.Security.Permissions;
54
using NHibernate.Properties;
65
using NHibernate.Util;
76

7+
#if FEATURE_SECURITY_PERMISSIONS
8+
using System.Security.Permissions;
9+
#endif
10+
811
namespace NHibernate.Bytecode.Lightweight
912
{
1013
public class ReflectionOptimizer : IReflectionOptimizer, IInstantiationOptimizer
@@ -100,9 +103,13 @@ protected virtual void ThrowExceptionForNoDefaultCtor(System.Type type)
100103
protected DynamicMethod CreateDynamicMethod(System.Type returnType, System.Type[] argumentTypes)
101104
{
102105
System.Type owner = mappedType.GetTypeInfo().IsInterface ? typeof (object) : mappedType;
106+
#if FEATURE_SECURITY_PERMISSIONS
103107
#pragma warning disable 618
104108
bool canSkipChecks = SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
105109
#pragma warning restore 618
110+
#else
111+
bool canSkipChecks = false;
112+
#endif
106113
return new DynamicMethod(string.Empty, returnType, argumentTypes, owner, canSkipChecks);
107114
}
108115

0 commit comments

Comments
 (0)