Skip to content

XamlLoadPermission.FromXml for element without class attribute throws NRE #213

Closed

Description

@hughbe
[Fact]
public void FromXml_NoClassAttribute_ThrowsNullReferenceException()
{
    var permission = new XamlLoadPermission(PermissionState.None);
    var elem = new SecurityElement("IPermission");
    permission.FromXml(elem);
}
  • Expected: throws ArgumentException to match other parse failures
  • Actual: throws NullReferenceException!

Cause

public override void FromXml(SecurityElement elem)
{
    if (elem == null)
    {
        throw new ArgumentNullException(nameof(elem));
    }
    if (elem.Tag != XmlConstants.IPermission)
    {
        throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedTag, elem.Tag, XmlConstants.IPermission), nameof(elem));
    }

    string className = elem.Attribute(XmlConstants.Class);
    if (!className.StartsWith(GetType().FullName, false, TypeConverterHelper.InvariantEnglishUS))
    {
        throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedValue, className, XmlConstants.Class, GetType().FullName), nameof(elem));
    }

Problem:

string className = elem.Attribute(XmlConstants.Class);
if (!className.StartsWith(GetType().FullName, false, TypeConverterHelper.InvariantEnglishUS))

The className can be null!

Activity

  1. added
    Bug
    on Apr 4, 2019
  2. added this to the 3.0 milestone on Apr 4, 2019
  3. modified the milestones: 3.0, Future on May 20, 2019
  4. vatsan-madhavan commented on May 29, 2019

    @vatsan-madhavan
    Member

    We are going to remove XamlLoadPermission's implementation from .NET Core 3.0 since CAS is no longer supported. Given this, I'm closing this issue.

    /c @ojhad

  5. ghost locked as resolved and limited conversation to collaborators on Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions