mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
CPP: Unify and improve the MallocCall classes.
This commit is contained in:
@@ -13,7 +13,10 @@ import cpp
|
||||
|
||||
class MallocCall extends FunctionCall
|
||||
{
|
||||
MallocCall() { this.getTarget().hasQualifiedName("malloc") }
|
||||
MallocCall() {
|
||||
this.getTarget().hasQualifiedName("malloc") or
|
||||
this.getTarget().hasQualifiedName("std::malloc")
|
||||
}
|
||||
|
||||
Expr getAllocatedSize() {
|
||||
if this.getArgument(0) instanceof VariableAccess then
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
*/
|
||||
import cpp
|
||||
|
||||
class MallocCall extends FunctionCall {
|
||||
MallocCall() { this.getTarget().hasGlobalName("malloc") }
|
||||
class MallocCall extends FunctionCall
|
||||
{
|
||||
MallocCall() {
|
||||
this.getTarget().hasQualifiedName("malloc") or
|
||||
this.getTarget().hasQualifiedName("std::malloc")
|
||||
}
|
||||
|
||||
Expr getAllocatedSize() {
|
||||
if this.getArgument(0) instanceof VariableAccess then
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
| tests1.cpp:26:21:26:26 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests1.cpp:67:21:67:26 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests1.cpp:89:25:89:30 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests3.cpp:25:21:25:31 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests3.cpp:30:21:30:31 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
| tests1.cpp:67:21:67:26 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests1.cpp:89:25:89:30 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests2.cpp:34:4:34:9 | call to strcat | This buffer only contains enough room for 'str1' (copied on line 33) |
|
||||
| tests3.cpp:25:21:25:31 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| tests3.cpp:30:21:30:31 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
|
||||
@@ -22,12 +22,12 @@ void tests3(int case_num)
|
||||
switch (case_num)
|
||||
{
|
||||
case 1:
|
||||
buffer = (char *)std::malloc(strlen(str3global)); // BAD [NOT DETECTED]
|
||||
buffer = (char *)std::malloc(strlen(str3global)); // BAD
|
||||
strcpy(buffer, str3global);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
buffer = (char *)std::malloc(strlen(str3local)); // BAD [NOT DETECTED]
|
||||
buffer = (char *)std::malloc(strlen(str3local)); // BAD
|
||||
strcpy(buffer, str3local);
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user