|
| 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