Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible null-dereference #574

Closed
wuestholz opened this issue Apr 14, 2016 · 3 comments
Closed

Possible null-dereference #574

wuestholz opened this issue Apr 14, 2016 · 3 comments
Labels

Comments

@wuestholz
Copy link
Contributor

There seems to be a possible null-dereference here.

The code below seems like a sensible fix:

DependentPlatforms = new List<DependentPlatform>();
ApiContracts = new List<ApiContract>();

if (rootElement != null)
{
    Name = rootElement.GetAttribute(Attributes.Name);
    FriendlyName = rootElement.GetAttribute(Attributes.FriendlyName);
    PlatformVersion = rootElement.GetAttribute(Attributes.Version);

    foreach (XmlNode childNode in rootElement.ChildNodes)
    {
        XmlElement childElement = childNode as XmlElement;
        if (childElement == null)
        {
            continue;
        }

        if (ApiContract.IsContainedApiContractsElement(childElement.Name))
        {
            ApiContract.ReadContractsElement(childElement, ApiContracts);
        }
        else if (String.Equals(childElement.Name, Elements.DependentPlatform, StringComparison.Ordinal))
        {
            DependentPlatforms.Add(new DependentPlatform(childElement.GetAttribute(Attributes.Name), childElement.GetAttribute(Attributes.Version)));
        }
    }
}
@rainersigwald
Copy link
Member

Agreed, and your fix looks reasonable to me. Would you like to submit a pull request?

@wuestholz
Copy link
Contributor Author

@rainersigwald Great! Thanks for having a look. I just created a PR.

@cdmihai
Copy link
Contributor

cdmihai commented Apr 27, 2016

LGTM.
Minor comment: is it or is it not an error if the xml file is there but the root element is not found?

AndyGerlicher added a commit that referenced this issue Apr 29, 2016
AndyGerlicher pushed a commit to AndyGerlicher/msbuild that referenced this issue May 2, 2016
Ensure that 'rootElement' is non-null when accessing its 'ChildNodes' property.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants