Skip to content

Commit 73c7bc1

Browse files
committed
CPP: Generalize a little.
1 parent 7fc31f2 commit 73c7bc1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cpp/ql/src/Security/CWE/CWE-131/NoSpaceForZeroTerminator.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
import cpp
1717
import semmle.code.cpp.dataflow.DataFlow
18+
import semmle.code.cpp.models.implementations.Memcpy
1819

1920
class MallocCall extends FunctionCall
2021
{
@@ -35,11 +36,12 @@ class MallocCall extends FunctionCall
3536

3637
predicate terminationProblem(MallocCall malloc, string msg) {
3738
malloc.getAllocatedSize() instanceof StrlenCall and
38-
not exists(DataFlow::Node def, DataFlow::Node use, FunctionCall fc |
39+
not exists(DataFlow::Node def, DataFlow::Node use, FunctionCall fc, MemcpyFunction memcpy, int ix |
3940
DataFlow::localFlow(def, use) and
4041
def.asExpr() = malloc and
41-
use.asExpr() = fc.getArgument(0) and
42-
fc.getTarget().hasName("memcpy")
42+
fc.getTarget() = memcpy and
43+
memcpy.hasArrayOutput(ix) and
44+
use.asExpr() = fc.getArgument(ix)
4345
) and
4446
msg = "This allocation does not include space to null-terminate the string."
4547
}

0 commit comments

Comments
 (0)