mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Split PolynomialRedos definition into a library to avoid duplication in the tests
This commit is contained in:
@@ -1,26 +1,6 @@
|
||||
import java
|
||||
import TestUtilities.InlineExpectationsTest
|
||||
import semmle.code.java.security.performance.SuperlinearBackTracking
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
import semmle.code.java.regex.RegexTreeView
|
||||
import semmle.code.java.regex.RegexFlowConfigs
|
||||
import semmle.code.java.dataflow.FlowSources
|
||||
|
||||
class PolynomialRedosSink extends DataFlow::Node {
|
||||
RegExpLiteral reg;
|
||||
|
||||
PolynomialRedosSink() { regexMatchedAgainst(reg.getRegex(), this.asExpr()) }
|
||||
|
||||
RegExpTerm getRegExp() { result.getParent() = reg }
|
||||
}
|
||||
|
||||
class PolynomialRedosConfig extends TaintTracking::Configuration {
|
||||
PolynomialRedosConfig() { this = "PolynomialRedosConfig" }
|
||||
|
||||
override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) { sink instanceof PolynomialRedosSink }
|
||||
}
|
||||
import semmle.code.java.security.performance.PolynomialReDosQuery
|
||||
|
||||
class HasPolyRedos extends InlineExpectationsTest {
|
||||
HasPolyRedos() { this = "HasPolyRedos" }
|
||||
@@ -29,15 +9,10 @@ class HasPolyRedos extends InlineExpectationsTest {
|
||||
|
||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
tag = "hasPolyRedos" and
|
||||
exists(
|
||||
PolynomialRedosConfig config, DataFlow::PathNode source, DataFlow::PathNode sink,
|
||||
PolynomialRedosSink sinkNode, PolynomialBackTrackingTerm regexp
|
||||
|
|
||||
config.hasFlowPath(source, sink) and
|
||||
sinkNode = sink.getNode() and
|
||||
regexp.getRootTerm() = sinkNode.getRegExp() and
|
||||
location = sinkNode.getLocation() and
|
||||
element = sinkNode.toString() and
|
||||
exists(DataFlow::PathNode source, DataFlow::PathNode sink, PolynomialBackTrackingTerm regexp |
|
||||
hasPolynomialReDosResult(source, sink, regexp) and
|
||||
location = sink.getNode().getLocation() and
|
||||
element = sink.getNode().toString() and
|
||||
value = ""
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user