Skip to content

Commit 022276b

Browse files
committed
Added model for gettext variants.
1 parent 643817e commit 022276b

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

cpp/ql/lib/semmle/code/cpp/models/Models.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ private import implementations.Deallocation
33
private import implementations.Fread
44
private import implementations.Getenv
55
private import implementations.Gets
6+
private import implementations.GetText
67
private import implementations.IdentityFunction
78
private import implementations.Inet
89
private import implementations.Iterator
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

0 commit comments

Comments
 (0)