File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
cpp/ql/lib/semmle/code/cpp/models Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ private import implementations.Deallocation
3
3
private import implementations.Fread
4
4
private import implementations.Getenv
5
5
private import implementations.Gets
6
+ private import implementations.GetText
6
7
private import implementations.IdentityFunction
7
8
private import implementations.Inet
8
9
private 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