mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
CPP: Basic fix.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
* external/cwe/cwe-122
|
||||
*/
|
||||
import cpp
|
||||
import semmle.code.cpp.dataflow.DataFlow
|
||||
|
||||
class MallocCall extends FunctionCall
|
||||
{
|
||||
@@ -34,6 +35,12 @@ class MallocCall extends FunctionCall
|
||||
|
||||
predicate terminationProblem(MallocCall malloc, string msg) {
|
||||
malloc.getAllocatedSize() instanceof StrlenCall and
|
||||
not exists(DataFlow::Node def, DataFlow::Node use, FunctionCall fc |
|
||||
DataFlow::localFlow(def, use) and
|
||||
def.asExpr() = malloc and
|
||||
use.asExpr() = fc.getArgument(0) and
|
||||
fc.getTarget().hasName("memcpy")
|
||||
) and
|
||||
msg = "This allocation does not include space to null-terminate the string."
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
| test.c:15:20:15:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| test.c:29:20:29:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| test.c:44:20:44:25 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| test.c:72:17:72:22 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
| test.cpp:18:35:18:40 | call to malloc | This allocation does not include space to null-terminate the string. |
|
||||
|
||||
@@ -67,7 +67,7 @@ void good3(char *str) {
|
||||
void *memcpy(void *s1, const void *s2, size_t n);
|
||||
|
||||
void good4(char *str) {
|
||||
// GOOD -- allocating a non zero-terminated string [FALSE POSITIVE]
|
||||
// GOOD -- allocating a non zero-terminated string
|
||||
int len = strlen(str);
|
||||
char *buffer = malloc(len);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user