Skip to content

Commit 9c72e73

Browse files
committed
Make ExecTainted easier to extend
To add a method that executes a command, you can now define a class extending ExecMethod.
1 parent 9362ae0 commit 9c72e73

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

java/ql/src/semmle/code/java/JDK.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import 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

java/ql/src/semmle/code/java/frameworks/apache/Exec.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/* Definitions related to the Apache Commons Exec library. */
22
import semmle.code.java.Type
3+
import semmle.code.java.security.ExternalProcess
34

45
library 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")

java/ql/src/semmle/code/java/security/ExternalProcess.qll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@ import semmle.code.java.Member
33
import semmle.code.java.JDK
44
import 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
*/
1116
class 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 |

0 commit comments

Comments
 (0)