-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Adds another rule for null deref #16524
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| char * create (int arg) { | ||
| if (arg > 42) { | ||
| // this function may return NULL | ||
| return NULL; | ||
| } | ||
| char * r = malloc(arg); | ||
| snprintf(r, arg -1, "Hello"); | ||
| return r; | ||
| } | ||
|
|
||
| void process(char *str) { | ||
| // str is dereferenced | ||
| if (str[0] == 'H') { | ||
| printf("Hello H\n"); | ||
| } | ||
| } | ||
|
|
||
| void test(int arg) { | ||
| // first function returns a pointer that may be NULL | ||
| char *str = create(arg); | ||
| // str is not checked for nullness before being passed to process function | ||
| process(str); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <!DOCTYPE qhelp PUBLIC | ||
| "-//Semmle//qhelp//EN" | ||
| "qhelp.dtd"> | ||
| <qhelp> | ||
|
|
||
| <overview> | ||
| <p>This rule finds a dereference of a function parameter, whose value comes from another function call that may return NULL, without checks in the meantime.</p> | ||
| </overview> | ||
|
|
||
| <recommendation> | ||
| <p>A check should be added between the return of the function which may return NULL, and its use by the function dereferencing ths pointer.</p> | ||
| </recommendation> | ||
|
|
||
| <example> | ||
| <sample src="DerefNullResult.cpp" /> | ||
| </example> | ||
|
|
||
| <references> | ||
| <li> | ||
| <a href="https://www.owasp.org/index.php/Null_Dereference"> | ||
| Null Dereference | ||
| </a> | ||
| </li> | ||
| </references> | ||
|
|
||
| </qhelp> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||
| /** | ||||||
| * @name Null dereference from a function result | ||||||
| * @description A function parameter is dereference, | ||||||
| * while it comes from a function that may return NULL, | ||||||
| * and is not checked for nullness by the caller. | ||||||
| * @kind problem | ||||||
| * @id cpp/deref-null-result | ||||||
| * @problem.severity recommendation | ||||||
| * @tags reliability | ||||||
| * security | ||||||
| * external/cwe/cwe-476 | ||||||
| */ | ||||||
|
|
||||||
| import cpp | ||||||
| import semmle.code.cpp.dataflow.DataFlow | ||||||
|
||||||
| import semmle.code.cpp.dataflow.DataFlow | |
| import semmle.code.cpp.dataflow.new.DataFlow |
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.
Just pushed that
Uh oh!
There was an error while loading. Please reload this page.