File tree Expand file tree Collapse file tree 3 files changed +13
-12
lines changed
java/ql/src/semmle/code/java Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 3
3
*/
4
4
5
5
import Member
6
+ import semmle.code.java.security.ExternalProcess
6
7
7
8
// --- Standard types ---
8
9
/** The class `java.lang.Object`. */
@@ -179,7 +180,7 @@ class TypeFile extends Class {
179
180
/**
180
181
* Any of the methods named `command` on class `java.lang.ProcessBuilder`.
181
182
*/
182
- class MethodProcessBuilderCommand extends Method {
183
+ class MethodProcessBuilderCommand extends ExecMethod {
183
184
MethodProcessBuilderCommand ( ) {
184
185
hasName ( "command" ) and
185
186
getDeclaringType ( ) instanceof TypeProcessBuilder
@@ -189,7 +190,7 @@ class MethodProcessBuilderCommand extends Method {
189
190
/**
190
191
* Any method named `exec` on class `java.lang.Runtime`.
191
192
*/
192
- class MethodRuntimeExec extends Method {
193
+ class MethodRuntimeExec extends ExecMethod {
193
194
MethodRuntimeExec ( ) {
194
195
hasName ( "exec" ) and
195
196
getDeclaringType ( ) instanceof TypeRuntime
Original file line number Diff line number Diff line change 1
1
/* Definitions related to the Apache Commons Exec library. */
2
2
import semmle.code.java.Type
3
+ import semmle.code.java.security.ExternalProcess
3
4
4
5
library class TypeCommandLine extends Class {
5
6
TypeCommandLine ( ) { hasQualifiedName ( "org.apache.commons.exec" , "CommandLine" ) }
6
7
}
7
8
8
- library class MethodCommandLineParse extends Method {
9
+ library class MethodCommandLineParse extends ExecMethod {
9
10
MethodCommandLineParse ( ) {
10
11
getDeclaringType ( ) instanceof TypeCommandLine and
11
12
hasName ( "parse" )
12
13
}
13
14
}
14
15
15
- library class MethodCommandLineAddArguments extends Method {
16
+ library class MethodCommandLineAddArguments extends ExecMethod {
16
17
MethodCommandLineAddArguments ( ) {
17
18
getDeclaringType ( ) instanceof TypeCommandLine and
18
19
hasName ( "addArguments" )
Original file line number Diff line number Diff line change @@ -3,22 +3,21 @@ import semmle.code.java.Member
3
3
import semmle.code.java.JDK
4
4
import semmle.code.java.frameworks.apache.Exec
5
5
6
+ /**
7
+ * A method that executes a command.
8
+ */
9
+ abstract class ExecMethod extends Method { }
10
+
6
11
/**
7
12
* An expression used as an argument to a call that executes an external command. For calls to
8
13
* varargs method calls, this only includes the first argument, which will be the command
9
14
* to be executed.
10
15
*/
11
16
class ArgumentToExec extends Expr {
12
17
ArgumentToExec ( ) {
13
- exists ( MethodAccess execCall , Method method |
18
+ exists ( MethodAccess execCall , ExecMethod method |
14
19
execCall .getArgument ( 0 ) = this and
15
- method = execCall .getMethod ( ) and
16
- (
17
- method instanceof MethodRuntimeExec or
18
- method instanceof MethodProcessBuilderCommand or
19
- method instanceof MethodCommandLineParse or
20
- method instanceof MethodCommandLineAddArguments
21
- )
20
+ method = execCall .getMethod ( )
22
21
)
23
22
or
24
23
exists ( ConstructorCall expr , Constructor cons |
You can’t perform that action at this time.
0 commit comments