@@ -4,42 +4,17 @@ import cpp
4
4
import semmle.code.cpp.security.FunctionWithWrappers
5
5
import semmle.code.cpp.models.interfaces.SideEffect
6
6
import semmle.code.cpp.models.interfaces.Alias
7
+ import semmle.code.cpp.models.interfaces.CommandExecution
7
8
8
- /**
9
- * A function for running a command using a command interpreter.
10
- */
11
- class SystemFunction extends FunctionWithWrappers , ArrayFunction , AliasFunction , SideEffectFunction {
12
- SystemFunction ( ) {
13
- hasGlobalOrStdName ( "system" ) or // system(command)
14
- hasGlobalName ( "popen" ) or // popen(command, mode)
15
- // Windows variants
16
- hasGlobalName ( "_popen" ) or // _popen(command, mode)
17
- hasGlobalName ( "_wpopen" ) or // _wpopen(command, mode)
18
- hasGlobalName ( "_wsystem" ) // _wsystem(command)
19
- }
20
-
21
- override predicate interestingArg ( int arg ) { arg = 0 }
22
-
23
- override predicate hasArrayWithNullTerminator ( int bufParam ) { bufParam = 0 or bufParam = 1 }
24
-
25
- override predicate hasArrayInput ( int bufParam ) { bufParam = 0 or bufParam = 1 }
26
-
27
- override predicate parameterNeverEscapes ( int index ) { index = 0 or index = 1 }
28
-
29
- override predicate parameterEscapesOnlyViaReturn ( int index ) { none ( ) }
30
-
31
- override predicate parameterIsAlwaysReturned ( int index ) { none ( ) }
32
-
33
- override predicate hasOnlySpecificReadSideEffects ( ) { any ( ) }
34
-
35
- override predicate hasOnlySpecificWriteSideEffects ( ) {
36
- hasGlobalOrStdName ( "system" ) or
37
- hasGlobalName ( "_wsystem" )
38
- }
39
-
40
- override predicate hasSpecificReadSideEffect ( ParameterIndex i , boolean buffer ) {
41
- ( i = 0 or i = 1 ) and
42
- buffer = true
9
+ class WrappedSystemFunction extends FunctionWithWrappers instanceof CommandExecutionFunction {
10
+ override predicate interestingArg ( int arg ) {
11
+ exists ( FunctionInput input |
12
+ this .( CommandExecutionFunction ) .hasCommandArgument ( input ) and
13
+ (
14
+ input .isParameterDerefOrQualifierObject ( arg ) or
15
+ input .isParameterOrQualifierAddress ( arg )
16
+ )
17
+ )
43
18
}
44
19
}
45
20
@@ -185,7 +160,7 @@ predicate shellCommandPreface(string cmd, string flag) {
185
160
*/
186
161
predicate shellCommand ( Expr command , string callChain ) {
187
162
// A call to a function like system()
188
- exists ( SystemFunction systemFunction |
163
+ exists ( WrappedSystemFunction systemFunction |
189
164
systemFunction .outermostWrapperFunctionCall ( command , callChain )
190
165
)
191
166
or
0 commit comments