Skip to content

Commit 3747bd9

Browse files
authored
Merge pull request github#3694 from geoffw0/models
C++: Extend the GetsFunction and SystemFunction models.
2 parents 9587097 + 466f36c commit 3747bd9

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Gets.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,17 @@ class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunction, Alias
4848
output.isParameterDeref(0) and
4949
description = "String read by " + this.getName()
5050
}
51+
52+
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {
53+
not hasGlobalOrStdName("gets") and
54+
bufParam = 0 and
55+
countParam = 1
56+
}
57+
58+
override predicate hasArrayWithUnknownSize(int bufParam) {
59+
hasGlobalOrStdName("gets") and
60+
bufParam = 0
61+
}
62+
63+
override predicate hasArrayOutput(int bufParam) { bufParam = 0 }
5164
}

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,44 @@
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 {
10+
class SystemFunction extends FunctionWithWrappers, ArrayFunction, AliasFunction, SideEffectFunction {
1011
SystemFunction() {
11-
hasGlobalOrStdName("system") or
12-
hasGlobalName("popen") or
12+
hasGlobalOrStdName("system") or // system(command)
13+
hasGlobalName("popen") or // popen(command, mode)
1314
// 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)
1718
}
1819

1920
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+
}
2043
}
2144

2245
/**

0 commit comments

Comments
 (0)