|
| 1 | +/** |
| 2 | + * @kind path-problem |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | +import semmle.code.java.dataflow.FlowSources |
| 7 | +import semmle.code.java.dataflow.DataFlow |
| 8 | +class Getter extends Method { |
| 9 | + Getter() { this.getName().regexpMatch("get.+") } |
| 10 | +} |
| 11 | + |
| 12 | +class Source extends Callable { |
| 13 | + Source() { |
| 14 | + this instanceof Getter and getDeclaringType().getASupertype*() instanceof TypeSerializable |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +class GetConnectionMethod extends Method { |
| 19 | + GetConnectionMethod() { |
| 20 | + this.hasName("getConnection") and |
| 21 | + this.getDeclaringType().hasQualifiedName("java.sql", "DriverManager") |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +class DangerousMethod extends Callable { |
| 26 | + DangerousMethod() { this instanceof GetConnectionMethod } |
| 27 | +} |
| 28 | + |
| 29 | +class CallsDangerousMethod extends Callable { |
| 30 | + CallsDangerousMethod() { |
| 31 | + exists(Callable a | |
| 32 | + this.polyCalls(a) and |
| 33 | + a instanceof DangerousMethod |
| 34 | + ) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +query predicate edges(Callable a, Callable b) { |
| 39 | + a.polyCalls(b) |
| 40 | +} |
| 41 | + |
| 42 | +from Source source, CallsDangerousMethod sink |
| 43 | +where edges+(source, sink) |
| 44 | +select source, source, sink, "$@ $@ to $@ $@", source.getDeclaringType(), |
| 45 | + source.getDeclaringType().getName(), source, source.getName(), sink.getDeclaringType(), |
| 46 | + sink.getDeclaringType().getName(), sink, sink.getName() |
0 commit comments