File tree Expand file tree Collapse file tree 3 files changed +28
-14
lines changed
java/ql/src/semmle/code/java Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -180,21 +180,34 @@ class TypeFile extends Class {
180
180
/**
181
181
* Any of the methods named `command` on class `java.lang.ProcessBuilder`.
182
182
*/
183
- class MethodProcessBuilderCommand extends ExecMethod {
183
+ class ProcessBuilderConstructor extends Constructor , ExecCallable {
184
+ ProcessBuilderConstructor ( ) { this .getDeclaringType ( ) instanceof TypeProcessBuilder }
185
+
186
+ override int getAnExecutedArgument ( ) { result = 0 }
187
+ }
188
+
189
+ /**
190
+ * Any of the methods named `command` on class `java.lang.ProcessBuilder`.
191
+ */
192
+ class MethodProcessBuilderCommand extends Method , ExecCallable {
184
193
MethodProcessBuilderCommand ( ) {
185
194
hasName ( "command" ) and
186
195
getDeclaringType ( ) instanceof TypeProcessBuilder
187
196
}
197
+
198
+ override int getAnExecutedArgument ( ) { result = 0 }
188
199
}
189
200
190
201
/**
191
202
* Any method named `exec` on class `java.lang.Runtime`.
192
203
*/
193
- class MethodRuntimeExec extends ExecMethod {
204
+ class MethodRuntimeExec extends Method , ExecCallable {
194
205
MethodRuntimeExec ( ) {
195
206
hasName ( "exec" ) and
196
207
getDeclaringType ( ) instanceof TypeRuntime
197
208
}
209
+
210
+ override int getAnExecutedArgument ( ) { result = 0 }
198
211
}
199
212
200
213
/**
Original file line number Diff line number Diff line change @@ -6,16 +6,20 @@ library class TypeCommandLine extends Class {
6
6
TypeCommandLine ( ) { hasQualifiedName ( "org.apache.commons.exec" , "CommandLine" ) }
7
7
}
8
8
9
- library class MethodCommandLineParse extends ExecMethod {
9
+ library class MethodCommandLineParse extends Method , ExecCallable {
10
10
MethodCommandLineParse ( ) {
11
11
getDeclaringType ( ) instanceof TypeCommandLine and
12
12
hasName ( "parse" )
13
13
}
14
+
15
+ override int getAnExecutedArgument ( ) { result = 0 }
14
16
}
15
17
16
- library class MethodCommandLineAddArguments extends ExecMethod {
18
+ library class MethodCommandLineAddArguments extends Method , ExecCallable {
17
19
MethodCommandLineAddArguments ( ) {
18
20
getDeclaringType ( ) instanceof TypeCommandLine and
19
21
hasName ( "addArguments" )
20
22
}
23
+
24
+ override int getAnExecutedArgument ( ) { result = 0 }
21
25
}
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import semmle.code.java.frameworks.apache.Exec
6
6
/**
7
7
* A method that executes a command.
8
8
*/
9
- abstract class ExecMethod extends Method { }
9
+ abstract class ExecCallable extends Callable {
10
+ abstract int getAnExecutedArgument ( ) ;
11
+ }
10
12
11
13
/**
12
14
* An expression used as an argument to a call that executes an external command. For calls to
@@ -15,15 +17,10 @@ abstract class ExecMethod extends Method { }
15
17
*/
16
18
class ArgumentToExec extends Expr {
17
19
ArgumentToExec ( ) {
18
- exists ( MethodAccess execCall , ExecMethod method |
19
- execCall .getArgument ( 0 ) = this and
20
- method = execCall .getMethod ( )
21
- )
22
- or
23
- exists ( ConstructorCall expr , Constructor cons |
24
- expr .getConstructor ( ) = cons and
25
- cons .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "ProcessBuilder" ) and
26
- expr .getArgument ( 0 ) = this
20
+ exists ( Call execCall , ExecCallable execCallable , int i |
21
+ execCall .getArgument ( i ) = this and
22
+ execCallable = execCall .getCallee ( ) and
23
+ i = execCallable .getAnExecutedArgument ( )
27
24
)
28
25
}
29
26
}
You can’t perform that action at this time.
0 commit comments