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 33 */
44
55import Member
6+ import semmle.code.java.security.ExternalProcess
67
78// --- Standard types ---
89/** The class `java.lang.Object`. */
@@ -179,7 +180,7 @@ class TypeFile extends Class {
179180/**
180181 * Any of the methods named `command` on class `java.lang.ProcessBuilder`.
181182 */
182- class MethodProcessBuilderCommand extends Method {
183+ class MethodProcessBuilderCommand extends ExecMethod {
183184 MethodProcessBuilderCommand ( ) {
184185 hasName ( "command" ) and
185186 getDeclaringType ( ) instanceof TypeProcessBuilder
@@ -189,7 +190,7 @@ class MethodProcessBuilderCommand extends Method {
189190/**
190191 * Any method named `exec` on class `java.lang.Runtime`.
191192 */
192- class MethodRuntimeExec extends Method {
193+ class MethodRuntimeExec extends ExecMethod {
193194 MethodRuntimeExec ( ) {
194195 hasName ( "exec" ) and
195196 getDeclaringType ( ) instanceof TypeRuntime
Original file line number Diff line number Diff line change 11/* Definitions related to the Apache Commons Exec library. */
22import semmle.code.java.Type
3+ import semmle.code.java.security.ExternalProcess
34
45library class TypeCommandLine extends Class {
56 TypeCommandLine ( ) { hasQualifiedName ( "org.apache.commons.exec" , "CommandLine" ) }
67}
78
8- library class MethodCommandLineParse extends Method {
9+ library class MethodCommandLineParse extends ExecMethod {
910 MethodCommandLineParse ( ) {
1011 getDeclaringType ( ) instanceof TypeCommandLine and
1112 hasName ( "parse" )
1213 }
1314}
1415
15- library class MethodCommandLineAddArguments extends Method {
16+ library class MethodCommandLineAddArguments extends ExecMethod {
1617 MethodCommandLineAddArguments ( ) {
1718 getDeclaringType ( ) instanceof TypeCommandLine and
1819 hasName ( "addArguments" )
Original file line number Diff line number Diff line change @@ -3,22 +3,21 @@ import semmle.code.java.Member
33import semmle.code.java.JDK
44import semmle.code.java.frameworks.apache.Exec
55
6+ /**
7+ * A method that executes a command.
8+ */
9+ abstract class ExecMethod extends Method { }
10+
611/**
712 * An expression used as an argument to a call that executes an external command. For calls to
813 * varargs method calls, this only includes the first argument, which will be the command
914 * to be executed.
1015 */
1116class ArgumentToExec extends Expr {
1217 ArgumentToExec ( ) {
13- exists ( MethodAccess execCall , Method method |
18+ exists ( MethodAccess execCall , ExecMethod method |
1419 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 ( )
2221 )
2322 or
2423 exists ( ConstructorCall expr , Constructor cons |
You can’t perform that action at this time.
0 commit comments