Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,25 +996,11 @@ ReleaseHolder<FriendAssemblyDescriptor> Assembly::GetFriendAssemblyInfo()

//*****************************************************************************
// Is the given assembly a friend of this assembly?
bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly, FieldDesc *pFD)
bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly)
{
WRAPPER_NO_CONTRACT;

return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly, pFD);
}

bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly, MethodDesc *pMD)
{
WRAPPER_NO_CONTRACT;

return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly, pMD);
}

bool Assembly::GrantsFriendAccessTo(Assembly *pAccessingAssembly, MethodTable *pMT)
{
WRAPPER_NO_CONTRACT;

return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly, pMT);
return GetFriendAssemblyInfo()->GrantsFriendAccessTo(pAccessingAssembly);
}

bool Assembly::IgnoresAccessChecksTo(Assembly *pAccessedAssembly)
Expand Down
12 changes: 2 additions & 10 deletions src/coreclr/vm/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,7 @@ class Assembly

//****************************************************************************************
// Is the given assembly a friend of this assembly?
bool GrantsFriendAccessTo(Assembly *pAccessingAssembly, FieldDesc *pFD);
bool GrantsFriendAccessTo(Assembly *pAccessingAssembly, MethodDesc *pMD);
bool GrantsFriendAccessTo(Assembly *pAccessingAssembly, MethodTable *pMT);
bool GrantsFriendAccessTo(Assembly *pAccessingAssembly);
bool IgnoresAccessChecksTo(Assembly *pAccessedAssembly);

#ifdef FEATURE_COMINTEROP
Expand Down Expand Up @@ -578,24 +576,18 @@ class FriendAssemblyDescriptor
//
// Arguments:
// pAccessingAssembly - the assembly requesting friend access
// pMember - the member that is attempting to be accessed
//
// Return Value:
// true if friend access is allowed, false otherwise
//
// Notes:
// Template type T should be either FieldDesc, MethodDesc, or MethodTable.
//

template <class T>
bool GrantsFriendAccessTo(Assembly *pAccessingAssembly, T *pMember)
bool GrantsFriendAccessTo(Assembly *pAccessingAssembly)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
PRECONDITION(CheckPointer(pAccessingAssembly));
PRECONDITION(CheckPointer(pMember));
}
CONTRACTL_END;

Expand Down
41 changes: 5 additions & 36 deletions src/coreclr/vm/clsload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4068,29 +4068,21 @@ void DECLSPEC_NORETURN ThrowTypeAccessException(MethodDesc* pCallerMD,
// Arguments:
// pAccessingAssembly - The assembly requesting access to the internal member
// pTargetAssembly - The assembly which contains the target member
// pOptionalTargetField - Internal field being accessed OR
// pOptionalTargetMethod - Internal type being accessed OR
// pOptionalTargetType - Internal type being accessed
//
// Return Value:
// TRUE if pTargetAssembly is pAccessingAssembly, or if pTargetAssembly allows
// pAccessingAssembly friend access to the target. FALSE otherwise.
//

static BOOL AssemblyOrFriendAccessAllowed(Assembly *pAccessingAssembly,
Assembly *pTargetAssembly,
FieldDesc *pOptionalTargetField,
MethodDesc *pOptionalTargetMethod,
MethodTable *pOptionalTargetType)
Assembly *pTargetAssembly)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
PRECONDITION(CheckPointer(pAccessingAssembly));
PRECONDITION(CheckPointer(pTargetAssembly));
PRECONDITION(pOptionalTargetField != NULL || pOptionalTargetMethod != NULL || pOptionalTargetType != NULL);
PRECONDITION(pOptionalTargetField == NULL || pOptionalTargetMethod == NULL);
}
CONTRACTL_END;

Expand All @@ -4103,18 +4095,9 @@ static BOOL AssemblyOrFriendAccessAllowed(Assembly *pAccessingAssembly,
{
return TRUE;
}

else if (pOptionalTargetField != NULL)
{
return pTargetAssembly->GrantsFriendAccessTo(pAccessingAssembly, pOptionalTargetField);
}
else if (pOptionalTargetMethod != NULL)
{
return pTargetAssembly->GrantsFriendAccessTo(pAccessingAssembly, pOptionalTargetMethod);
}
else
{
return pTargetAssembly->GrantsFriendAccessTo(pAccessingAssembly, pOptionalTargetType);
return pTargetAssembly->GrantsFriendAccessTo(pAccessingAssembly);
}
}

Expand Down Expand Up @@ -4247,10 +4230,7 @@ BOOL ClassLoader::CanAccessClass( // True if access is legal,
_ASSERTE(pCurrentAssembly != NULL);

if (AssemblyOrFriendAccessAllowed(pCurrentAssembly,
pTargetAssembly,
NULL,
NULL,
pTargetClass))
pTargetAssembly))
{
return TRUE;
}
Expand Down Expand Up @@ -4290,7 +4270,7 @@ BOOL ClassLoader::CanAccessClass( // True if access is legal,
// protection, we can fail the request now. Otherwise we can check to make sure a public member
// of the outer class is allowed, since we have satisfied the target's accessibility rules.

if (AssemblyOrFriendAccessAllowed(pContext->GetCallerAssembly(), pTargetAssembly, NULL, NULL, pTargetClass))
if (AssemblyOrFriendAccessAllowed(pContext->GetCallerAssembly(), pTargetAssembly))
dwProtection = (dwProtection == tdNestedFamANDAssem) ? mdFamily : mdPublic;
else if (dwProtection == tdNestedFamORAssem)
dwProtection = mdFamily;
Expand All @@ -4314,7 +4294,6 @@ BOOL ClassLoader::CanAccessClass( // True if access is legal,
pTargetAssembly,
dwProtection,
NULL,
NULL,
accessCheckOptions);
} // BOOL ClassLoader::CanAccessClass()

Expand All @@ -4331,7 +4310,6 @@ BOOL ClassLoader::CanAccess( // TRUE if access is all
DWORD dwMemberAccess, // Member access flags of the desired target member (as method bits).
MethodDesc* pOptionalTargetMethod, // The target method; NULL if the target is a not a method or
// there is no need to check the method's instantiation.
FieldDesc* pOptionalTargetField, // or The desired field; if NULL, return TRUE
const AccessCheckOptions & accessCheckOptions) // = s_NormalAccessChecks
{
CONTRACT(BOOL)
Expand All @@ -4351,7 +4329,6 @@ BOOL ClassLoader::CanAccess( // TRUE if access is all
pTargetAssembly,
dwMemberAccess,
pOptionalTargetMethod,
pOptionalTargetField,
// Suppress exceptions for nested classes since this is not a hard-failure,
// and we can do additional checks
accessCheckOptionsNoThrow))
Expand Down Expand Up @@ -4384,7 +4361,6 @@ BOOL ClassLoader::CanAccess( // TRUE if access is all
pTargetAssembly,
dwMemberAccess,
pOptionalTargetMethod,
pOptionalTargetField,
accessCheckOptionsNoThrow);
}

Expand Down Expand Up @@ -4414,7 +4390,6 @@ BOOL ClassLoader::CheckAccessMember( // TRUE if access is allowed
DWORD dwMemberAccess, // Member access flags of the desired target member (as method bits).
MethodDesc* pOptionalTargetMethod, // The target method; NULL if the target is a not a method or
// there is no need to check the method's instantiation.
FieldDesc* pOptionalTargetField, // target field, NULL if there is no Target field
const AccessCheckOptions & accessCheckOptions
)
{
Expand Down Expand Up @@ -4449,9 +4424,6 @@ BOOL ClassLoader::CheckAccessMember( // TRUE if access is allowed
return FALSE;
}

// pOptionalTargetMethod and pOptionalTargetField can never be NULL at the same time.
_ASSERTE(pOptionalTargetMethod == NULL || pOptionalTargetField == NULL);

// Perform transparency checks
// We don't need to do transparency check against pTargetMT here because
// it was already done in CanAccessClass above.
Expand Down Expand Up @@ -4503,10 +4475,7 @@ BOOL ClassLoader::CheckAccessMember( // TRUE if access is allowed
_ASSERTE(pCurrentAssembly != NULL);

const BOOL fAssemblyOrFriendAccessAllowed = AssemblyOrFriendAccessAllowed(pCurrentAssembly,
pTargetAssembly,
pOptionalTargetField,
pOptionalTargetMethod,
pTargetMT);
pTargetAssembly);

if ((pTargetMT == NULL || IsMdAssem(dwMemberAccess) || IsMdFamORAssem(dwMemberAccess)) &&
fAssemblyOrFriendAccessAllowed)
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/clsload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ class ClassLoader
Assembly* pTargetAssembly,
DWORD dwMemberAttrs,
MethodDesc* pOptionalTargetMethod,
FieldDesc* pOptionalTargetField,
const AccessCheckOptions & accessCheckOptions = *AccessCheckOptions::s_pNormalAccessChecks);

private:
Expand All @@ -847,7 +846,6 @@ class ClassLoader
Assembly* pTargetAssembly,
DWORD dwMemberAttrs,
MethodDesc* pOptionalTargetMethod,
FieldDesc* pOptionalTargetField,
const AccessCheckOptions & accessCheckOptions = *AccessCheckOptions::s_pNormalAccessChecks);


Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4748,8 +4748,7 @@ HRESULT FindPredefinedILStubMethod(MethodDesc *pTargetMD, DWORD dwStubFlags, Met
pStubClassMT,
stubClassType.GetAssembly(),
pStubMD->GetAttrs(),
pStubMD,
NULL))
pStubMD))
{
StackSString interopMethodName(SString::Utf8, pTargetMD->GetName());

Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,6 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
fieldTypeForSecurity.GetAssembly(),
fieldAttribs,
NULL,
(flags & CORINFO_ACCESS_INIT_ARRAY) ? NULL : pField, // For InitializeArray, we don't need tocheck the type of the field.
accessCheckOptions);

if (!canAccess)
Expand Down Expand Up @@ -5450,7 +5449,6 @@ void CEEInfo::getCallInfo(
calleeTypeForSecurity.GetAssembly(),
pCalleeForSecurity->GetAttrs(),
pCalleeForSecurity,
NULL,
accessCheckOptions
);

Expand Down Expand Up @@ -13107,7 +13105,6 @@ static TADDR UnsafeJitFunctionWorker(
ownerTypeForSecurity.GetAssembly(),
pMethodForSecurity->GetAttrs(),
pMethodForSecurity,
NULL,
accessCheckOptions))
{
EX_THROW(EEMethodException, (pMethodForSecurity));
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/methodtablebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4710,7 +4710,7 @@ BOOL MethodTableBuilder::TestOverrideForAccessibility(
if (IsMdCheckAccessOnOverride(dwParentAttrs))
{
// Same Assembly
if (isSameAssembly || pParentAssembly->GrantsFriendAccessTo(pChildAssembly, hParentMethod.GetMethodDesc())
if (isSameAssembly || pParentAssembly->GrantsFriendAccessTo(pChildAssembly)
|| pChildAssembly->IgnoresAccessChecksTo(pParentAssembly))
{
// Can always override any method that has accessibility greater than mdPrivate
Expand Down Expand Up @@ -4813,7 +4813,7 @@ VOID MethodTableBuilder::TestOverRide(bmtMethodHandle hParentMethod,
WIDENING_STATUS entry = rgWideningTable[idxMember][idxParent];

if (entry == e_NO ||
(entry == e_SA && !isSameAssembly && !pParentAssembly->GrantsFriendAccessTo(pAssembly, hParentMethod.GetMethodDesc())
(entry == e_SA && !isSameAssembly && !pParentAssembly->GrantsFriendAccessTo(pAssembly)
&& !pAssembly->IgnoresAccessChecksTo(pParentAssembly)) ||
(entry == e_NSA && isSameAssembly) ||
(entry == e_SM && !isSameModule)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/runtimehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ static BOOL CheckCAVisibilityFromDecoratedType(MethodTable* pCAMT, MethodDesc* p
pCAMT->GetAssembly(),
dwAttr,
pCACtor,
NULL,
*AccessCheckOptions::s_pNormalAccessChecks);
}

Expand Down
Loading