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 {
180180/**
181181 * Any of the methods named `command` on class `java.lang.ProcessBuilder`.
182182 */
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 {
184193 MethodProcessBuilderCommand ( ) {
185194 hasName ( "command" ) and
186195 getDeclaringType ( ) instanceof TypeProcessBuilder
187196 }
197+
198+ override int getAnExecutedArgument ( ) { result = 0 }
188199}
189200
190201/**
191202 * Any method named `exec` on class `java.lang.Runtime`.
192203 */
193- class MethodRuntimeExec extends ExecMethod {
204+ class MethodRuntimeExec extends Method , ExecCallable {
194205 MethodRuntimeExec ( ) {
195206 hasName ( "exec" ) and
196207 getDeclaringType ( ) instanceof TypeRuntime
197208 }
209+
210+ override int getAnExecutedArgument ( ) { result = 0 }
198211}
199212
200213/**
Original file line number Diff line number Diff line change @@ -6,16 +6,20 @@ library class TypeCommandLine extends Class {
66 TypeCommandLine ( ) { hasQualifiedName ( "org.apache.commons.exec" , "CommandLine" ) }
77}
88
9- library class MethodCommandLineParse extends ExecMethod {
9+ library class MethodCommandLineParse extends Method , ExecCallable {
1010 MethodCommandLineParse ( ) {
1111 getDeclaringType ( ) instanceof TypeCommandLine and
1212 hasName ( "parse" )
1313 }
14+
15+ override int getAnExecutedArgument ( ) { result = 0 }
1416}
1517
16- library class MethodCommandLineAddArguments extends ExecMethod {
18+ library class MethodCommandLineAddArguments extends Method , ExecCallable {
1719 MethodCommandLineAddArguments ( ) {
1820 getDeclaringType ( ) instanceof TypeCommandLine and
1921 hasName ( "addArguments" )
2022 }
23+
24+ override int getAnExecutedArgument ( ) { result = 0 }
2125}
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import semmle.code.java.frameworks.apache.Exec
66/**
77 * A method that executes a command.
88 */
9- abstract class ExecMethod extends Method { }
9+ abstract class ExecCallable extends Callable {
10+ abstract int getAnExecutedArgument ( ) ;
11+ }
1012
1113/**
1214 * 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 { }
1517 */
1618class ArgumentToExec extends Expr {
1719 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 ( )
2724 )
2825 }
2926}
You can’t perform that action at this time.
0 commit comments