|
| 1 | +/** |
| 2 | + * Provides implementation classes modeling `accept` and various similar |
| 3 | + * functions. See `semmle.code.cpp.models.Models` for usage information. |
| 4 | + */ |
| 5 | + |
| 6 | +import semmle.code.cpp.Function |
| 7 | +import semmle.code.cpp.models.interfaces.ArrayFunction |
| 8 | +import semmle.code.cpp.models.interfaces.Taint |
| 9 | +import semmle.code.cpp.models.interfaces.Alias |
| 10 | +import semmle.code.cpp.models.interfaces.SideEffect |
| 11 | + |
| 12 | +/** |
| 13 | + * The function `accept` and its assorted variants |
| 14 | + */ |
| 15 | +private class Accept extends ArrayFunction, AliasFunction, TaintFunction, SideEffectFunction { |
| 16 | + Accept() { this.hasGlobalName(["accept", "accept4", "WSAAccept"]) } |
| 17 | + |
| 18 | + override predicate hasArrayWithVariableSize(int bufParam, int countParam) { |
| 19 | + bufParam = 1 and countParam = 2 |
| 20 | + } |
| 21 | + |
| 22 | + override predicate hasArrayInput(int bufParam) { bufParam = 1 } |
| 23 | + |
| 24 | + override predicate hasArrayOutput(int bufParam) { bufParam = 1 } |
| 25 | + |
| 26 | + override predicate parameterNeverEscapes(int index) { exists(this.getParameter(index)) } |
| 27 | + |
| 28 | + override predicate parameterEscapesOnlyViaReturn(int index) { none() } |
| 29 | + |
| 30 | + override predicate parameterIsAlwaysReturned(int index) { none() } |
| 31 | + |
| 32 | + override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
| 33 | + (input.isParameter(0) or input.isParameterDeref(1)) and |
| 34 | + (output.isReturnValue() or output.isParameterDeref(1)) |
| 35 | + } |
| 36 | + |
| 37 | + override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) { |
| 38 | + i = 1 and buffer = true and mustWrite = false |
| 39 | + or |
| 40 | + i = 2 and buffer = false and mustWrite = false |
| 41 | + } |
| 42 | + |
| 43 | + override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) { |
| 44 | + i = 0 and buffer = true |
| 45 | + or |
| 46 | + i = 1 and buffer = false |
| 47 | + } |
| 48 | + |
| 49 | + override ParameterIndex getParameterSizeIndex(ParameterIndex i) { i = 1 and result = 2 } |
| 50 | + |
| 51 | + // NOTE: We implement thse two predicates as none because we can't model the low-level changes made to |
| 52 | + // the structure pointed to by the file-descriptor argument. |
| 53 | + override predicate hasOnlySpecificReadSideEffects() { none() } |
| 54 | + |
| 55 | + override predicate hasOnlySpecificWriteSideEffects() { none() } |
| 56 | +} |
0 commit comments