@@ -4,42 +4,20 @@ import cpp
44import semmle.code.cpp.security.FunctionWithWrappers
55import semmle.code.cpp.models.interfaces.SideEffect
66import semmle.code.cpp.models.interfaces.Alias
7+ import semmle.code.cpp.models.interfaces.CommandExecution
78
89/**
910 * A function for running a command using a command interpreter.
1011 */
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
12+ class SystemFunction extends FunctionWithWrappers instanceof CommandExecutionFunction {
13+ override predicate interestingArg ( int arg ) {
14+ exists ( FunctionInput input |
15+ this .( CommandExecutionFunction ) .hasCommandArgument ( input ) and
16+ (
17+ input .isParameterDerefOrQualifierObject ( arg ) or
18+ input .isParameterOrQualifierAddress ( arg )
19+ )
20+ )
4321 }
4422}
4523
0 commit comments