File tree Expand file tree Collapse file tree
cpp/ql/lib/semmle/code/cpp/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ private import implementations.Deallocation
33private import implementations.Fread
44private import implementations.Getenv
55private import implementations.Gets
6+ private import implementations.GetText
67private import implementations.IdentityFunction
78private import implementations.Inet
89private import implementations.Iterator
Original file line number Diff line number Diff line change 1+ import semmle.code.cpp.models.interfaces.DataFlow
2+
3+ /**
4+ * Returns the transated text index for a given gettext function `f`
5+ */
6+ private int getTextArg ( Function f ) {
7+ // basic variations of gettext
8+ f .hasGlobalOrStdName ( "gettext" ) and result = 0
9+ or
10+ f .hasGlobalOrStdName ( "dgettext" ) and result = 1
11+ or
12+ f .hasGlobalOrStdName ( "dcgettext" ) and result = 1
13+ or
14+ // plural variations of gettext that take one format string for singular and another for plural form
15+ f .hasGlobalOrStdName ( "ngettext" ) and
16+ ( result = 0 or result = 1 )
17+ or
18+ f .hasGlobalOrStdName ( "dngettext" ) and
19+ ( result = 1 or result = 2 )
20+ or
21+ f .hasGlobalOrStdName ( "dcngettext" ) and
22+ ( result = 1 or result = 2 )
23+ }
24+
25+ class GetTextFunction extends DataFlowFunction {
26+ int argInd ;
27+
28+ GetTextFunction ( ) { argInd = getTextArg ( this ) }
29+
30+ override predicate hasDataFlow ( FunctionInput input , FunctionOutput output ) {
31+ input .isParameter ( argInd ) and output .isReturnValue ( )
32+ or
33+ input .isParameterDeref ( argInd ) and output .isReturnValueDeref ( )
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments