11/* Definitions related to external processes. */
22import semmle.code.java.Member
3- import semmle.code.java.JDK
4- import semmle.code.java.frameworks.apache.Exec
3+
4+ private module Instances {
5+ private import semmle.code.java.JDK
6+ private import semmle.code.java.frameworks.apache.Exec
7+ }
8+
9+ /**
10+ * A callable that executes a command.
11+ */
12+ abstract class ExecCallable extends Callable {
13+ /**
14+ * Gets the index of an argument that will be part of the command that is executed.
15+ */
16+ abstract int getAnExecutedArgument ( ) ;
17+ }
518
619/**
720 * An expression used as an argument to a call that executes an external command. For calls to
@@ -10,21 +23,10 @@ import semmle.code.java.frameworks.apache.Exec
1023 */
1124class ArgumentToExec extends Expr {
1225 ArgumentToExec ( ) {
13- exists ( MethodAccess execCall , Method method |
14- 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- )
22- )
23- or
24- exists ( ConstructorCall expr , Constructor cons |
25- expr .getConstructor ( ) = cons and
26- cons .getDeclaringType ( ) .hasQualifiedName ( "java.lang" , "ProcessBuilder" ) and
27- expr .getArgument ( 0 ) = this
26+ exists ( Call execCall , ExecCallable execCallable , int i |
27+ execCall .getArgument ( pragma [ only_bind_into ] ( i ) ) = this and
28+ execCallable = execCall .getCallee ( ) and
29+ i = execCallable .getAnExecutedArgument ( )
2830 )
2931 }
3032}
0 commit comments