|
2 | 2 |
|
3 | 3 | import cpp
|
4 | 4 | import semmle.code.cpp.security.FunctionWithWrappers
|
| 5 | +import semmle.code.cpp.models.interfaces.SideEffect |
5 | 6 |
|
6 | 7 | /**
|
7 | 8 | * A function for running a command using a command interpreter.
|
8 | 9 | */
|
9 |
| -class SystemFunction extends FunctionWithWrappers { |
| 10 | +class SystemFunction extends FunctionWithWrappers, ArrayFunction, AliasFunction, SideEffectFunction { |
10 | 11 | SystemFunction() {
|
11 |
| - hasGlobalOrStdName("system") or |
12 |
| - hasGlobalName("popen") or |
| 12 | + hasGlobalOrStdName("system") or // system(command) |
| 13 | + hasGlobalName("popen") or // popen(command, mode) |
13 | 14 | // Windows variants
|
14 |
| - hasGlobalName("_popen") or |
15 |
| - hasGlobalName("_wpopen") or |
16 |
| - hasGlobalName("_wsystem") |
| 15 | + hasGlobalName("_popen") or // _popen(command, mode) |
| 16 | + hasGlobalName("_wpopen") or // _wpopen(command, mode) |
| 17 | + hasGlobalName("_wsystem") // _wsystem(command) |
17 | 18 | }
|
18 | 19 |
|
19 | 20 | override predicate interestingArg(int arg) { arg = 0 }
|
| 21 | + |
| 22 | + override predicate hasArrayWithNullTerminator(int bufParam) { bufParam = 0 or bufParam = 1 } |
| 23 | + |
| 24 | + override predicate hasArrayInput(int bufParam) { bufParam = 0 or bufParam = 1 } |
| 25 | + |
| 26 | + override predicate parameterNeverEscapes(int index) { index = 0 or index = 1 } |
| 27 | + |
| 28 | + override predicate parameterEscapesOnlyViaReturn(int index) { none() } |
| 29 | + |
| 30 | + override predicate parameterIsAlwaysReturned(int index) { none() } |
| 31 | + |
| 32 | + override predicate hasOnlySpecificReadSideEffects() { any() } |
| 33 | + |
| 34 | + override predicate hasOnlySpecificWriteSideEffects() { |
| 35 | + hasGlobalOrStdName("system") or |
| 36 | + hasGlobalName("_wsystem") |
| 37 | + } |
| 38 | + |
| 39 | + override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) { |
| 40 | + (i = 0 or i = 1) and |
| 41 | + buffer = true |
| 42 | + } |
20 | 43 | }
|
21 | 44 |
|
22 | 45 | /**
|
|
0 commit comments