1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Protected protection improvements

This commit is contained in:
Brian Fiete 2020-12-06 07:32:01 -08:00
parent 670de8d4dc
commit 8852e7e194
7 changed files with 94 additions and 36 deletions

View file

@ -33,7 +33,7 @@ namespace System.Threading.Tasks
} }
public this(delegate TResult(Object) func, Object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions) public this(delegate TResult(Object) func, Object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
: this(func, state, Task.[Friend]InternalCurrentIfAttached(creationOptions), cancellationToken, : this(func, state, Task.InternalCurrentIfAttached(creationOptions), cancellationToken,
creationOptions, InternalTaskOptions.None, null) creationOptions, InternalTaskOptions.None, null)
{ {
//StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; //StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;

View file

@ -752,7 +752,7 @@ namespace System.Reflection
{ {
get get
{ {
return (TypeInstance)Type.[Friend]GetType(mBaseType); return (TypeInstance)Type.GetType(mBaseType);
} }
} }
@ -768,7 +768,7 @@ namespace System.Reflection
{ {
get get
{ {
return (TypeInstance)Type.[Friend]GetType(mOuterType); return (TypeInstance)Type.GetType(mOuterType);
} }
} }
@ -776,7 +776,7 @@ namespace System.Reflection
{ {
get get
{ {
return Type.[Friend]GetType(mUnderlyingType); return Type.GetType(mUnderlyingType);
} }
} }
@ -803,7 +803,7 @@ namespace System.Reflection
return true; return true;
if (curType.mBaseType == 0) if (curType.mBaseType == 0)
return false; return false;
curType = (TypeInstance)Type.[Friend]GetType(curType.mBaseType); curType = (TypeInstance)Type.GetType(curType.mBaseType);
} }
} }
@ -921,7 +921,7 @@ namespace System.Reflection
{ {
get get
{ {
return Type.[Friend]GetType(mElementType); return Type.GetType(mElementType);
} }
} }
@ -951,7 +951,7 @@ namespace System.Reflection
{ {
get get
{ {
return Type.[Friend]GetType(mElementType); return Type.GetType(mElementType);
} }
} }
@ -978,7 +978,7 @@ namespace System.Reflection
{ {
get get
{ {
return Type.[Friend]GetType(mElementType); return Type.GetType(mElementType);
} }
} }
@ -1015,14 +1015,14 @@ namespace System.Reflection
[Ordered, AlwaysInclude(AssumeInstantiated=true)] [Ordered, AlwaysInclude(AssumeInstantiated=true)]
class SpecializedGenericType : TypeInstance class SpecializedGenericType : TypeInstance
{ {
TypeId mUnspecializedType; protected TypeId mUnspecializedType;
TypeId* mResolvedTypeRefs; protected TypeId* mResolvedTypeRefs;
public Type UnspecializedType public Type UnspecializedType
{ {
get get
{ {
return Type.[Friend]GetType(mUnspecializedType); return Type.GetType(mUnspecializedType);
} }
} }
@ -1030,7 +1030,7 @@ namespace System.Reflection
{ {
get get
{ {
var unspecializedTypeG = Type.[Friend]GetType(mUnspecializedType); var unspecializedTypeG = Type.GetType(mUnspecializedType);
var unspecializedType = (UnspecializedGenericType)unspecializedTypeG; var unspecializedType = (UnspecializedGenericType)unspecializedTypeG;
return unspecializedType.[Friend]mGenericParamCount; return unspecializedType.[Friend]mGenericParamCount;
} }
@ -1043,7 +1043,7 @@ namespace System.Reflection
public override void GetFullName(String strBuffer) public override void GetFullName(String strBuffer)
{ {
var unspecializedTypeG = Type.[Friend]GetType(mUnspecializedType); var unspecializedTypeG = Type.GetType(mUnspecializedType);
var unspecializedType = (UnspecializedGenericType)unspecializedTypeG; var unspecializedType = (UnspecializedGenericType)unspecializedTypeG;
base.GetFullName(strBuffer); base.GetFullName(strBuffer);
@ -1059,7 +1059,7 @@ namespace System.Reflection
{ {
if (i > 0) if (i > 0)
strBuffer.Append(", "); strBuffer.Append(", ");
Type.[Friend]GetType(mResolvedTypeRefs[i]).GetFullName(strBuffer); Type.GetType(mResolvedTypeRefs[i]).GetFullName(strBuffer);
} }
strBuffer.Append('>'); strBuffer.Append('>');
} }
@ -1075,7 +1075,7 @@ namespace System.Reflection
public override void GetFullName(String strBuffer) public override void GetFullName(String strBuffer)
{ {
Type.[Friend]GetType(mResolvedTypeRefs[0]).GetFullName(strBuffer); Type.GetType(mResolvedTypeRefs[0]).GetFullName(strBuffer);
strBuffer.Append('['); strBuffer.Append('[');
for (int commaNum < mRank - 1) for (int commaNum < mRank - 1)
strBuffer.Append(','); strBuffer.Append(',');

View file

@ -49,6 +49,16 @@ namespace Tests
{ {
mAPriv mAPriv
} }
private static void PrivA2()
{
}
protected static void ProtA2()
{
}
} }
class ClassB : ClassA class ClassB : ClassA
@ -70,7 +80,11 @@ namespace Tests
{ {
var ca = new ClassA(); //FAIL var ca = new ClassA(); //FAIL
base.PrivA(); //FAIL base.PrivA(); //FAIL
base.ProtA();
ca.GetPriv!(); ca.GetPriv!();
ClassA.PrivA2(); //FAIL
ClassA.ProtA2();
} }
protected void ProtB() protected void ProtB()
@ -103,6 +117,8 @@ namespace Tests
ca.mAProt = 1; //FAIL ca.mAProt = 1; //FAIL
mAPriv = 1; //FAIL mAPriv = 1; //FAIL
mAProt = 1; mAProt = 1;
base.mAPriv = 1; //FAIL
base.mAProt = 1;
} }
} }

View file

@ -2129,7 +2129,20 @@ bool BfMethodMatcher::CheckType(BfTypeInstance* typeInstance, BfTypedValue targe
if (curTypeDef->mMethodSet.TryGetWith(mMethodName, &entry)) if (curTypeDef->mMethodSet.TryGetWith(mMethodName, &entry))
nextMethodDef = (BfMethodDef*)entry->mMemberDef; nextMethodDef = (BfMethodDef*)entry->mMemberDef;
} }
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None; BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
if (target)
{
if (mBypassVirtual)
{
// Not an "instance lookup"
}
else
{
protectionCheckFlags = (BfProtectionCheckFlags)(protectionCheckFlags | BfProtectionCheckFlag_InstanceLookup);
}
}
while (nextMethodDef != NULL) while (nextMethodDef != NULL)
{ {
bool allowExplicitInterface = curTypeInst->IsInterface() && mBypassVirtual; bool allowExplicitInterface = curTypeInst->IsInterface() && mBypassVirtual;
@ -3933,6 +3946,18 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
} }
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None; BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
if (target)
{
if ((flags & (BfLookupFieldFlag_IsImplicitThis | BfLookupFieldFlag_BaseLookup)) != 0)
{
// Not an "instance lookup"
}
else
{
protectionCheckFlags = (BfProtectionCheckFlags)(protectionCheckFlags | BfProtectionCheckFlag_InstanceLookup);
}
}
BfFieldDef* matchedField = NULL; BfFieldDef* matchedField = NULL;
while (nextField != NULL) while (nextField != NULL)
{ {
@ -8607,7 +8632,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
} }
if (mPropDef == NULL) if (mPropDef == NULL)
mResult = LookupField(nameRight, lookupVal, fieldName); mResult = LookupField(nameRight, lookupVal, fieldName, CheckIsBase(nameLeft) ? BfLookupFieldFlag_BaseLookup : BfLookupFieldFlag_None);
if ((!mResult) && (mPropDef == NULL) && (lookupType->IsGenericParam())) if ((!mResult) && (mPropDef == NULL) && (lookupType->IsGenericParam()))
{ {
@ -17888,12 +17913,9 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
// Try first as a non-static indexer, then as a static indexer // Try first as a non-static indexer, then as a static indexer
for (int pass = 0; pass < 2; pass++) for (int pass = 0; pass < 2; pass++)
{ {
// SetAndRestoreValue<bool> prevIgnoreErrors(mModule->mIgnoreErrors, (mModule->mIgnoreErrors) || (pass == 0)); ///
// SetAndRestoreValue<bool> prevHadIgnoredError(mModule->mHadIgnoredError, false);
{ {
SetAndRestoreValue<BfEvalExprFlags> prevFlags(mBfEvalExprFlags, (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_NoLookupError)); SetAndRestoreValue<BfEvalExprFlags> prevFlags(mBfEvalExprFlags, (BfEvalExprFlags)(mBfEvalExprFlags | BfEvalExprFlags_NoLookupError), pass == 0);
VisitChild(indexerExpr->mTarget); VisitChild(indexerExpr->mTarget);
} }
ResolveGenericType(); ResolveGenericType();

View file

@ -319,9 +319,10 @@ enum BfLookupFieldFlags
{ {
BfLookupFieldFlag_None = 0, BfLookupFieldFlag_None = 0,
BfLookupFieldFlag_IsImplicitThis = 1, BfLookupFieldFlag_IsImplicitThis = 1,
BfLookupFieldFlag_CheckingOuter = 2, BfLookupFieldFlag_BaseLookup = 2,
BfLookupFieldFlag_IgnoreProtection = 4, BfLookupFieldFlag_CheckingOuter = 4,
BfLookupFieldFlag_BindOnly = 8 BfLookupFieldFlag_IgnoreProtection = 8,
BfLookupFieldFlag_BindOnly = 0x10
}; };
enum BfUnaryOpFlags enum BfUnaryOpFlags

View file

@ -2584,19 +2584,37 @@ bool BfModule::CheckProtection(BfProtectionCheckFlags& flags, BfTypeInstance* me
curCheckType = mixinOwner; curCheckType = mixinOwner;
} }
auto lookupCheckType = lookupStartType; if ((flags & BfProtectionCheckFlag_InstanceLookup) != 0)
while (lookupCheckType->mInheritDepth >= curCheckType->mInheritDepth)
{ {
if (lookupCheckType == curCheckType) auto lookupCheckType = lookupStartType;
while (lookupCheckType->mInheritDepth >= curCheckType->mInheritDepth)
{ {
allowProtected = true; if (lookupCheckType == curCheckType)
break; {
allowProtected = true;
break;
}
if (lookupCheckType == memberOwner)
break;
lookupCheckType = lookupCheckType->mBaseType;
if (lookupCheckType == NULL)
break;
}
}
else
{
auto lookupCheckType = curCheckType;
while (lookupCheckType->mInheritDepth >= memberOwner->mInheritDepth)
{
if (lookupCheckType == memberOwner)
{
allowProtected = true;
break;
}
lookupCheckType = lookupCheckType->mBaseType;
if (lookupCheckType == NULL)
break;
} }
if (lookupCheckType == memberOwner)
break;
lookupCheckType = lookupCheckType->mBaseType;
if (lookupCheckType == NULL)
break;
} }
if (!allowProtected) if (!allowProtected)

View file

@ -112,6 +112,7 @@ enum BfProtectionCheckFlags
BfProtectionCheckFlag_CheckedPrivate = 2, BfProtectionCheckFlag_CheckedPrivate = 2,
BfProtectionCheckFlag_AllowProtected = 4, BfProtectionCheckFlag_AllowProtected = 4,
BfProtectionCheckFlag_AllowPrivate = 8, BfProtectionCheckFlag_AllowPrivate = 8,
BfProtectionCheckFlag_InstanceLookup = 0x10
}; };
enum BfEmbeddedStatementFlags enum BfEmbeddedStatementFlags