Skip to content

Commit e70f22c

Browse files
committed
C++: Model getdelim and friends
1 parent 90d473d commit e70f22c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ private import implementations.Strdup
1414
private import implementations.Strftime
1515
private import implementations.StdString
1616
private import implementations.Swap
17+
private import implementations.GetDelim
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import semmle.code.cpp.models.interfaces.Taint
2+
import semmle.code.cpp.models.interfaces.Alias
3+
import semmle.code.cpp.models.interfaces.SideEffect
4+
import semmle.code.cpp.models.interfaces.FlowSource
5+
6+
/**
7+
* The standard functions `getdelim`, `getwdelim` and the glibc variant `__getdelim`.
8+
*/
9+
class GetDelimFunction extends TaintFunction, AliasFunction, SideEffectFunction, RemoteFlowFunction {
10+
GetDelimFunction() { hasGlobalName(["getdelim", "getwdelim", "__getdelim"]) }
11+
12+
override predicate hasTaintFlow(FunctionInput i, FunctionOutput o) {
13+
i.isParameter(3) and o.isParameterDeref(0)
14+
}
15+
16+
override predicate parameterNeverEscapes(int index) { index = [0, 1, 3] }
17+
18+
override predicate parameterEscapesOnlyViaReturn(int index) { none() }
19+
20+
override predicate parameterIsAlwaysReturned(int index) { none() }
21+
22+
override predicate hasOnlySpecificReadSideEffects() { any() }
23+
24+
override predicate hasOnlySpecificWriteSideEffects() { any() }
25+
26+
override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) {
27+
i = [0, 1] and
28+
buffer = false and
29+
mustWrite = true
30+
}
31+
32+
override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) {
33+
i = 3 and buffer = false
34+
}
35+
36+
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
37+
output.isParameterDeref(0) and
38+
description = "String read by " + this.getName()
39+
}
40+
}

0 commit comments

Comments
 (0)