-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
fix for possible Null Reference Exception #112412
Conversation
Tagging subscribers to this area: @dotnet/area-system-xml |
XmlNode n = LoadNode(true)!; | ||
|
||
// Move to the next node | ||
if (n.NodeType != XmlNodeType.Attribute) | ||
if (n != null && n.NodeType != XmlNodeType.Attribute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null-forgiving operator in the previous line explicitly expressed that null shouldn't be returned in this case.
Reading through the implementation, null can only be returned in case of malformed xml (end element without starting element). In this case, the behavior should be reconsidered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be more appropriate to fix it like this then?
XmlNode? n = LoadNode(true);
Debug.Assert(n != null);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip. I used option with "Debug.Assert".
/ba-g unrelated timeouts due to overloaded queues |
Should i push this changes to other branches (release/*)? |
No. Backporting to release branches should be done by area owner. This PR doesn't have real impact and doesn't meet the criteria. |
Method "LoadNode" returns the nullable type "XmlNode?". So, maybe we need to check "n" for "null" here?
Found by Linux Verification Center (linuxtesting.org) with SVACE.