1616 */
1717
1818import semmle.code.cpp.ir.dataflow.TaintTracking
19+ import semmle.code.cpp.models.implementations.GetText
1920import semmle.code.cpp.commons.Printf
2021
2122// For the following `...gettext` functions, we assume that
@@ -26,30 +27,21 @@ predicate whitelistFunction(Function f, int arg) {
2627 // basic variations of gettext
2728 f .getName ( ) = "_" and arg = 0
2829 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+ )
4434}
4535
46- // we assume that ALL uses of the `_` macro
36+ // we assume that ALL uses of the `_` macro (and calls to `gettext`)
4737// return constant string literals
4838predicate underscoreMacro ( Expr e ) {
4939 exists ( MacroInvocation mi |
5040 mi .getMacroName ( ) = "_" and
5141 mi .getExpr ( ) = e
5242 )
43+ or
44+ e = any ( GetTextFunction gettext ) .getACallToThisFunction ( )
5345}
5446
5547/**
0 commit comments