Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

PVS-Studio: fixed vulnerability CWE-476 (NULL Pointer Dereference) #16807

Merged
merged 10 commits into from Mar 10, 2017
2 changes: 1 addition & 1 deletion src/Common/src/System/Net/CaseInsensitiveAscii.cs
Expand Up @@ -43,7 +43,7 @@ internal class CaseInsensitiveAscii : IEqualityComparer, IComparer
public int GetHashCode(object myObject)
{
string myString = myObject as string;
if (myObject == null)
if (myString == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use object.ReferenceEquals to avoid calling the equality operator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roslyn is smart enough to avoid the string equality operator when comparing null, so object.ReferenceEquals isn't necessary.

{
return 0;
}
Expand Down
Expand Up @@ -103,7 +103,7 @@ internal CompilerInfo(CompilerParameters compilerParams, string codeDomProviderT
public override bool Equals(object o)
{
CompilerInfo other = o as CompilerInfo;
if (o == null)
if (other == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that all of our tests were passing before this change suggests that we're missing some test coverage. To go along with your fixes, can you add tests that would have failed before the changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be glad to do this, but I doubt that my manager would approve these actions. Most likely he will say something "We are a small company and cannot develop Microsoft projects for free" :) If you wish, I could give you contacts of our CEO and you could discuss variants of paid collaboration. We really could fix all the warnings and write tests, we do such tasks. Here is the example of how we did it for Unreal Engine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, we consider src/tests to be a unit, such that we ask contributors changing src to ensure that the tests for the thing being changed are appropriate. Doing so helps to ensure that the fix is actually a fix (and not a regression, as it was in the case of one of your changes you backed out... imagine how bad things could have been if we didn't have those tests and we merged the change). We can skip doing so this time for the few remaining modifications, but for any future contributions please do so. Thanks for the interest in contributing!

{
return false;
}
Expand Down
Expand Up @@ -222,7 +222,7 @@ private void InitializeArrays(string[] tabClassNames, Type[] tabClasses, Propert
}
else if (tabClassNames != null)
{
if (tabScopes != null && tabClasses.Length != tabScopes.Length)
if (tabScopes != null && tabClassNames.Length != tabScopes.Length)
{
throw new ArgumentException(SR.PropertyTabAttributeArrayLengthMismatch);
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Data.Common/src/System/Data/SimpleType.cs
Expand Up @@ -364,7 +364,7 @@ internal string HasConflictingDefinition(SimpleType otherSimpleType)

if (!string.Equals(BaseType, otherSimpleType.BaseType, StringComparison.Ordinal))
return ("BaseType");
if ((BaseSimpleType == null && otherSimpleType.BaseSimpleType != null) &&
if ((BaseSimpleType != null && otherSimpleType.BaseSimpleType != null) &&
(BaseSimpleType.HasConflictingDefinition(otherSimpleType.BaseSimpleType)).Length != 0)
return ("BaseSimpleType");
return string.Empty;
Expand Down
Expand Up @@ -19,7 +19,7 @@ public int Compare(object a, object b)
{
XmlNode nodeA = a as XmlNode;
XmlNode nodeB = b as XmlNode;
if ((a == null) || (b == null))
if ((nodeA == null) || (nodeB == null))
throw new ArgumentException();
int namespaceCompare = string.CompareOrdinal(nodeA.NamespaceURI, nodeB.NamespaceURI);
if (namespaceCompare != 0) return namespaceCompare;
Expand Down
Expand Up @@ -18,7 +18,7 @@ public int Compare(object a, object b)
{
XmlNode nodeA = a as XmlNode;
XmlNode nodeB = b as XmlNode;
if ((a == null) || (b == null))
if ((nodeA == null) || (nodeB == null))
throw new ArgumentException();
bool nodeAdefault = Utils.IsDefaultNamespaceNode(nodeA);
bool nodeBdefault = Utils.IsDefaultNamespaceNode(nodeB);
Expand Down