diff --git a/cpp/ql/src/semmle/code/cpp/models/implementations/Strdup.qll b/cpp/ql/src/semmle/code/cpp/models/implementations/Strdup.qll index f130b1d1b79..a53757a528a 100644 --- a/cpp/ql/src/semmle/code/cpp/models/implementations/Strdup.qll +++ b/cpp/ql/src/semmle/code/cpp/models/implementations/Strdup.qll @@ -1,9 +1,12 @@ import semmle.code.cpp.models.interfaces.Allocation +import semmle.code.cpp.models.interfaces.ArrayFunction +import semmle.code.cpp.models.interfaces.DataFlow +import semmle.code.cpp.models.interfaces.Taint /** * A `strdup` style allocation function. */ -class StrdupFunction extends AllocationFunction { +class StrdupFunction extends AllocationFunction, ArrayFunction, DataFlowFunction { StrdupFunction() { exists(string name | hasGlobalOrStdName(name) and @@ -28,4 +31,15 @@ class StrdupFunction extends AllocationFunction { ) ) } + + override predicate hasArrayInput(int bufParam) { bufParam = 0 } + + override predicate hasArrayWithNullTerminator(int bufParam) { bufParam = 0 } + + override predicate hasDataFlow(FunctionInput input, FunctionOutput output) { + // These always copy the full value of the input buffer to the result + // buffer + input.isParameterDeref(0) and + output.isReturnValueDeref() + } }