diff --git a/cpp/ql/src/semmle/code/cpp/models/implementations/Pure.qll b/cpp/ql/src/semmle/code/cpp/models/implementations/Pure.qll index dd03d83848c..5d8aec74733 100644 --- a/cpp/ql/src/semmle/code/cpp/models/implementations/Pure.qll +++ b/cpp/ql/src/semmle/code/cpp/models/implementations/Pure.qll @@ -44,6 +44,10 @@ class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunction, SideE getParameter(bufParam).getUnspecifiedType() instanceof PointerType } + override predicate hasArrayWithNullTerminator(int bufParam) { + getParameter(bufParam).getUnspecifiedType() instanceof PointerType + } + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { exists(ParameterIndex i | input.isParameter(i) and diff --git a/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/NoSpaceForZeroTerminator.expected b/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/NoSpaceForZeroTerminator.expected index 8d06485d334..4500779812b 100644 --- a/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/NoSpaceForZeroTerminator.expected +++ b/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/NoSpaceForZeroTerminator.expected @@ -6,4 +6,6 @@ | test.cpp:24:35:24:40 | call to malloc | This allocation does not include space to null-terminate the string. | | test.cpp:63:28:63:33 | call to malloc | This allocation does not include space to null-terminate the string. | | test.cpp:71:28:71:33 | call to malloc | This allocation does not include space to null-terminate the string. | +| test.cpp:79:28:79:33 | call to malloc | This allocation does not include space to null-terminate the string. | +| test.cpp:89:35:89:40 | call to malloc | This allocation does not include space to null-terminate the string. | | test.cpp:106:24:106:48 | new[] | This allocation does not include space to null-terminate the string. | diff --git a/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/test.cpp b/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/test.cpp index 832d98766a7..5be98851b3d 100644 --- a/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/test.cpp +++ b/cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator/test.cpp @@ -75,7 +75,7 @@ void bad6(char *str, char *dest) { } void bad7(char *str, char *str2) { - // BAD -- zero-termination proved by strcmp [NOT DETECTED] + // BAD -- zero-termination proved by strcmp char *buffer = (char *)malloc(strlen(str)); decode(buffer, str); if (strcmp(buffer, str2) == 0) { @@ -85,7 +85,7 @@ void bad7(char *str, char *str2) { } void bad8(wchar_t *str) { - // BAD -- zero-termination proved by wcslen [NOT DETECTED] + // BAD -- zero-termination proved by wcslen wchar_t *wbuffer = (wchar_t *)malloc(wcslen(str)); wdecode(wbuffer, str); if (wcslen(wbuffer) == 0) {