mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
Make ExecTainted easier to extend
To add a method that executes a command, you can now define a class extending ExecMethod.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import Member
|
||||
import semmle.code.java.security.ExternalProcess
|
||||
|
||||
// --- Standard types ---
|
||||
/** The class `java.lang.Object`. */
|
||||
@@ -179,7 +180,7 @@ class TypeFile extends Class {
|
||||
/**
|
||||
* Any of the methods named `command` on class `java.lang.ProcessBuilder`.
|
||||
*/
|
||||
class MethodProcessBuilderCommand extends Method {
|
||||
class MethodProcessBuilderCommand extends ExecMethod {
|
||||
MethodProcessBuilderCommand() {
|
||||
hasName("command") and
|
||||
getDeclaringType() instanceof TypeProcessBuilder
|
||||
@@ -189,7 +190,7 @@ class MethodProcessBuilderCommand extends Method {
|
||||
/**
|
||||
* Any method named `exec` on class `java.lang.Runtime`.
|
||||
*/
|
||||
class MethodRuntimeExec extends Method {
|
||||
class MethodRuntimeExec extends ExecMethod {
|
||||
MethodRuntimeExec() {
|
||||
hasName("exec") and
|
||||
getDeclaringType() instanceof TypeRuntime
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
/* Definitions related to the Apache Commons Exec library. */
|
||||
import semmle.code.java.Type
|
||||
import semmle.code.java.security.ExternalProcess
|
||||
|
||||
library class TypeCommandLine extends Class {
|
||||
TypeCommandLine() { hasQualifiedName("org.apache.commons.exec", "CommandLine") }
|
||||
}
|
||||
|
||||
library class MethodCommandLineParse extends Method {
|
||||
library class MethodCommandLineParse extends ExecMethod {
|
||||
MethodCommandLineParse() {
|
||||
getDeclaringType() instanceof TypeCommandLine and
|
||||
hasName("parse")
|
||||
}
|
||||
}
|
||||
|
||||
library class MethodCommandLineAddArguments extends Method {
|
||||
library class MethodCommandLineAddArguments extends ExecMethod {
|
||||
MethodCommandLineAddArguments() {
|
||||
getDeclaringType() instanceof TypeCommandLine and
|
||||
hasName("addArguments")
|
||||
|
||||
@@ -3,6 +3,11 @@ import semmle.code.java.Member
|
||||
import semmle.code.java.JDK
|
||||
import semmle.code.java.frameworks.apache.Exec
|
||||
|
||||
/**
|
||||
* A method that executes a command.
|
||||
*/
|
||||
abstract class ExecMethod extends Method { }
|
||||
|
||||
/**
|
||||
* An expression used as an argument to a call that executes an external command. For calls to
|
||||
* varargs method calls, this only includes the first argument, which will be the command
|
||||
@@ -10,15 +15,9 @@ import semmle.code.java.frameworks.apache.Exec
|
||||
*/
|
||||
class ArgumentToExec extends Expr {
|
||||
ArgumentToExec() {
|
||||
exists(MethodAccess execCall, Method method |
|
||||
exists(MethodAccess execCall, ExecMethod method |
|
||||
execCall.getArgument(0) = this and
|
||||
method = execCall.getMethod() and
|
||||
(
|
||||
method instanceof MethodRuntimeExec or
|
||||
method instanceof MethodProcessBuilderCommand or
|
||||
method instanceof MethodCommandLineParse or
|
||||
method instanceof MethodCommandLineAddArguments
|
||||
)
|
||||
method = execCall.getMethod()
|
||||
)
|
||||
or
|
||||
exists(ConstructorCall expr, Constructor cons |
|
||||
|
||||
Reference in New Issue
Block a user