16
16
*/
17
17
18
18
import semmle.code.cpp.ir.dataflow.TaintTracking
19
+ import semmle.code.cpp.models.implementations.GetText
19
20
import semmle.code.cpp.commons.Printf
20
21
21
22
// For the following `...gettext` functions, we assume that
@@ -26,30 +27,21 @@ predicate whitelistFunction(Function f, int arg) {
26
27
// basic variations of gettext
27
28
f .getName ( ) = "_" and arg = 0
28
29
or
29
- f .getName ( ) = "gettext" and arg = 0
30
- or
31
- f .getName ( ) = "dgettext" and arg = 1
32
- or
33
- f .getName ( ) = "dcgettext" and arg = 1
34
- or
35
- // plural variations of gettext that take one format string for singular and another for plural form
36
- f .getName ( ) = "ngettext" and
37
- ( arg = 0 or arg = 1 )
38
- or
39
- f .getName ( ) = "dngettext" and
40
- ( arg = 1 or arg = 2 )
41
- or
42
- f .getName ( ) = "dcngettext" and
43
- ( arg = 1 or arg = 2 )
30
+ exists ( FunctionInput input |
31
+ f .( GetTextFunction ) .hasDataFlow ( input , _) and
32
+ input .isParameterDeref ( arg )
33
+ )
44
34
}
45
35
46
- // we assume that ALL uses of the `_` macro
36
+ // we assume that ALL uses of the `_` macro (and calls to `gettext`)
47
37
// return constant string literals
48
38
predicate underscoreMacro ( Expr e ) {
49
39
exists ( MacroInvocation mi |
50
40
mi .getMacroName ( ) = "_" and
51
41
mi .getExpr ( ) = e
52
42
)
43
+ or
44
+ e = any ( GetTextFunction gettext ) .getACallToThisFunction ( )
53
45
}
54
46
55
47
/**
0 commit comments