Skip to content

Commit 1fefa98

Browse files
committed
Rename RegexMatch and only include expressions
1 parent 953ff9f commit 1fefa98

File tree

6 files changed

+21
-61
lines changed

6 files changed

+21
-61
lines changed

java/ql/lib/semmle/code/java/Concepts.qll

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,35 @@ overlay[local?]
77
module;
88

99
import java
10-
private import semmle.code.java.dataflow.DataFlow
1110
private import semmle.code.java.frameworks.JavaxAnnotations
1211

1312
/**
14-
* A data-flow node that executes a regular expression.
13+
* An expression that represents a regular expression match.
1514
*
1615
* Extend this class to refine existing API models. If you want to model new APIs,
17-
* extend `RegexExecution::Range` instead.
16+
* extend `RegexMatch::Range` instead.
1817
*/
19-
class RegexExecution extends DataFlow::Node instanceof RegexExecution::Range {
20-
/** Gets the data flow node for the regex being executed by this node. */
21-
DataFlow::Node getRegex() { result = super.getRegex() }
18+
class RegexMatch extends Expr instanceof RegexMatch::Range {
19+
/** Gets the expression for the regex being executed by this node. */
20+
Expr getRegex() { result = super.getRegex() }
2221

23-
/** Gets a data flow node for the string to be searched or matched against. */
24-
DataFlow::Node getString() { result = super.getString() }
22+
/** Gets an expression for the string to be searched or matched against. */
23+
Expr getString() { result = super.getString() }
2524

2625
/**
27-
* Gets the name of this regex execution, typically the name of an executing method.
26+
* Gets the name of this regex match, typically the name of an executing method.
2827
* This is used for nice alert messages and should include the module if possible.
2928
*/
3029
string getName() { result = super.getName() }
3130
}
3231

33-
/** Provides classes for modeling new regular-expression execution APIs. */
34-
module RegexExecution {
35-
/**
36-
* A data flow node that executes a regular expression.
37-
*
38-
* Extend this class to model new APIs. If you want to refine existing API models,
39-
* extend `RegexExecution` instead.
40-
*/
41-
abstract class Range extends DataFlow::Node {
42-
/** Gets the data flow node for the regex being executed by this node. */
43-
abstract DataFlow::Node getRegex();
44-
45-
/** Gets a data flow node for the string to be searched or matched against. */
46-
abstract DataFlow::Node getString();
47-
48-
/**
49-
* Gets the name of this regex execution, typically the name of an executing method.
50-
* This is used for nice alert messages and should include the module if possible.
51-
*/
52-
abstract string getName();
53-
}
54-
55-
private class RangeFromExpr extends Range {
56-
private RegexExecutionExpr::Range ree;
57-
58-
RangeFromExpr() { this.asExpr() = ree }
59-
60-
override DataFlow::Node getRegex() { result.asExpr() = ree.getRegex() }
61-
62-
override DataFlow::Node getString() { result.asExpr() = ree.getString() }
63-
64-
override string getName() { result = ree.getName() }
65-
}
66-
}
67-
68-
/** Provides classes for modeling new regular-expression execution APIs. */
69-
module RegexExecutionExpr {
32+
/** Provides classes for modeling regular-expression execution APIs. */
33+
module RegexMatch {
7034
/**
7135
* An expression that executes a regular expression.
7236
*
7337
* Extend this class to model new APIs. If you want to refine existing API models,
74-
* extend `RegexExecution` instead.
38+
* extend `RegexMatch` instead.
7539
*/
7640
abstract class Range extends Expr {
7741
/** Gets the expression for the regex being executed by this node. */
@@ -81,7 +45,7 @@ module RegexExecutionExpr {
8145
abstract Expr getString();
8246

8347
/**
84-
* Gets the name of this regex execution, typically the name of an executing method.
48+
* Gets the name of this regex match, typically the name of an executing method.
8549
* This is used for nice alert messages and should include the module if possible.
8650
*/
8751
abstract string getName();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class StringContainsMethod extends Method {
4848
}
4949

5050
/** A call to the `java.lang.String.matches` method. */
51-
class StringMatchesCall extends MethodCall, RegexExecutionExpr::Range {
51+
class StringMatchesCall extends MethodCall, RegexMatch::Range {
5252
StringMatchesCall() {
5353
exists(Method m | m = this.getMethod() |
5454
m.getDeclaringType() instanceof TypeString and

java/ql/lib/semmle/code/java/frameworks/JavaxAnnotations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class WebServiceRefAnnotation extends Annotation {
171171
/**
172172
* A `@javax.validation.constraints.Pattern` annotation.
173173
*/
174-
class PatternAnnotation extends Annotation, RegexExecutionExpr::Range {
174+
class PatternAnnotation extends Annotation, RegexMatch::Range {
175175
PatternAnnotation() {
176176
this.getType()
177177
.hasQualifiedName(["javax.validation.constraints", "jakarta.validation.constraints"],

java/ql/lib/semmle/code/java/frameworks/Regex.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class PatternMatcherCall extends MethodCall {
8282
}
8383

8484
/** A call to the `matches` method of `java.util.regex.Pattern`. */
85-
class PatternMatchesCall extends MethodCall, RegexExecutionExpr::Range {
85+
class PatternMatchesCall extends MethodCall, RegexMatch::Range {
8686
PatternMatchesCall() { this.getMethod() instanceof PatternMatchesMethod }
8787

8888
override Expr getRegex() { result = this.getArgument(0) }
@@ -93,7 +93,7 @@ class PatternMatchesCall extends MethodCall, RegexExecutionExpr::Range {
9393
}
9494

9595
/** A call to the `matches` method of `java.util.regex.Matcher`. */
96-
class MatcherMatchesCall extends MethodCall, RegexExecutionExpr::Range {
96+
class MatcherMatchesCall extends MethodCall, RegexMatch::Range {
9797
MatcherMatchesCall() { this.getMethod() instanceof MatcherMatchesMethod }
9898

9999
/**

java/ql/lib/semmle/code/java/security/PathSanitizer.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ private class ReplaceDirectoryCharactersSanitizer extends StringReplaceOrReplace
431431
* Holds if `matchesCall` confirms that `checkedExpr` does not contain any directory characters
432432
* on the given `branch`.
433433
*/
434-
private predicate isMatchesCall(
435-
RegexExecutionExpr::Range regexMatch, Expr checkedExpr, boolean branch
436-
) {
434+
private predicate isMatchesCall(RegexMatch regexMatch, Expr checkedExpr, boolean branch) {
437435
exists(CompileTimeConstantExpr target, string targetValue |
438436
target = regexMatch.getRegex() and
439437
target.getStringValue() = targetValue and

java/ql/lib/semmle/code/java/security/Sanitizers.qll

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class SimpleTypeSanitizer extends DataFlow::Node {
4141
* make the type recursive. Otherwise use `RegexpCheckBarrier`.
4242
*/
4343
predicate regexpMatchGuardChecks(Guard guard, Expr e, boolean branch) {
44-
exists(RegexExecutionExpr::Range ree | not ree instanceof Annotation |
45-
guard = ree and
46-
e = ree.getString()
44+
exists(RegexMatch rm | not rm instanceof Annotation |
45+
guard = rm and
46+
e = rm.getString()
4747
) and
4848
branch = true
4949
}
@@ -60,8 +60,6 @@ class RegexpCheckBarrier extends DataFlow::Node {
6060
// Annotations don't fit into the model of barrier guards because the
6161
// annotation doesn't dominate the sanitized expression, so we instead
6262
// treat them as barriers directly.
63-
exists(RegexExecutionExpr::Range ree | ree instanceof Annotation |
64-
this.asExpr() = ree.getString()
65-
)
63+
exists(RegexMatch rm | rm instanceof Annotation | this.asExpr() = rm.getString())
6664
}
6765
}

0 commit comments

Comments
 (0)