-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPrintfLike.qll
More file actions
28 lines (26 loc) · 917 Bytes
/
PrintfLike.qll
File metadata and controls
28 lines (26 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* Provides a predicate for identifying formatting functions like `printf`.
*
* Consider using the newer model in
* `semmle.code.cpp.models.interfaces.FormattingFunction` directly instead of
* this library.
*/
import semmle.code.cpp.commons.Printf
import external.ExternalArtifact
/**
* Holds if `func` is a `printf`-like formatting function and `formatArg` is
* the index of the format string argument.
*/
predicate printfLikeFunction(Function func, int formatArg) {
formatArg = func.(FormattingFunction).getFormatParameterIndex() and
not func instanceof UserDefinedFormattingFunction
or
primitiveVariadicFormatter(func, _, formatArg, _)
or
exists(ExternalData data |
// TODO Do this \ to / conversion in the toolchain?
data.getDataPath().replaceAll("\\", "/") = "cert/formatingFunction.csv" and
func.getName() = data.getField(0) and
formatArg = data.getFieldAsInt(1)
)
}