Skip to content

Commit fdd7ad2

Browse files
committed
C++: Add a SideEffectFunction model to 'system'.
1 parent e8b34e0 commit fdd7ad2

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cpp/ql/src/semmle/code/cpp/security/CommandExecution.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import cpp
44
import semmle.code.cpp.security.FunctionWithWrappers
5+
import semmle.code.cpp.models.interfaces.SideEffect
56

67
/**
78
* A function for running a command using a command interpreter.
89
*/
9-
class SystemFunction extends FunctionWithWrappers, ArrayFunction, AliasFunction {
10+
class SystemFunction extends FunctionWithWrappers, ArrayFunction, AliasFunction, SideEffectFunction {
1011
SystemFunction() {
1112
hasGlobalOrStdName("system") or // system(command)
1213
hasGlobalName("popen") or // popen(command, mode)
@@ -27,6 +28,18 @@ class SystemFunction extends FunctionWithWrappers, ArrayFunction, AliasFunction
2728
override predicate parameterEscapesOnlyViaReturn(int index) { none() }
2829

2930
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+
}
3043
}
3144

3245
/**

0 commit comments

Comments
 (0)