CPP: Add qhelp for RedundantNullCheckSimple.ql.

This commit is contained in:
Geoffrey White
2019-04-18 12:47:07 +01:00
parent f33b24c917
commit eaed0004a3
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
int f(MyList *list) {
list->append(1);
// ...
if (list != NULL)
{
list->append(2);
}
}

View File

@@ -0,0 +1,29 @@
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>This rule finds comparisons of a pointer to null that occur after a reference of that pointer. It's
likely either the check is not required and can be removed, or it should be moved to before the dereference
so that a null pointer dereference does not occur.</p>
</overview>
<recommendation>
<p>The check should be moved to before the dereference, in a way that prevents a null pointer value from
being dereferenced. If it's clear that the pointer cannot be null, consider removing the check instead.</p>
</recommendation>
<example>
<sample src="RedundantNullCheckSimple.cpp" />
</example>
<references>
<li>
<a href="https://www.owasp.org/index.php/Null_Dereference">
Null Dereference
</a>
</li>
</references>
</qhelp>