Skip to content

Commit 8b65937

Browse files
committed
Move ConstantStringExpr to RangeUtils.qll
1 parent bc08d67 commit 8b65937

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

java/ql/lib/semmle/code/java/dataflow/RangeUtils.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ private predicate constantBooleanExpr(Expr e, boolean val) {
104104
CalcConstants::calculateBooleanValue(e) = val
105105
}
106106

107+
pragma[nomagic]
108+
private predicate constantStringExpr(Expr e, string val) {
109+
e.(CompileTimeConstantExpr).getStringValue() = val
110+
or
111+
exists(SsaExplicitUpdate v, Expr src |
112+
e = v.getAUse() and
113+
src = v.getDefiningExpr().(VariableAssign).getSource() and
114+
constantStringExpr(src, val)
115+
)
116+
}
117+
107118
private boolean getBoolValue(Expr e) { constantBooleanExpr(e, result) }
108119

109120
private int getIntValue(Expr e) { constantIntegerExpr(e, result) }
@@ -126,6 +137,14 @@ class ConstantBooleanExpr extends Expr {
126137
boolean getBooleanValue() { constantBooleanExpr(this, result) }
127138
}
128139

140+
/** An expression that always has the same string value. */
141+
class ConstantStringExpr extends Expr {
142+
ConstantStringExpr() { constantStringExpr(this, _) }
143+
144+
/** Get the string value of this expression. */
145+
string getStringValue() { constantStringExpr(this, result) }
146+
}
147+
129148
/**
130149
* Gets an expression that equals `v - d`.
131150
*/

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import java
44
import semmle.code.java.dataflow.DataFlow
55
import semmle.code.java.dataflow.DataFlow2
66
import semmle.code.java.dataflow.DataFlow3
7-
import semmle.code.java.dataflow.DataFlow4
8-
import semmle.code.java.dataflow.DataFlow5
9-
private import semmle.code.java.dataflow.SSA
7+
private import semmle.code.java.dataflow.RangeUtils
108

119
/*
1210
* Various XML parsers in Java.
@@ -130,26 +128,6 @@ class DocumentBuilderFactoryConfig extends ParserConfig {
130128
}
131129
}
132130

133-
private predicate constantStringExpr(Expr e, string val) {
134-
e.(CompileTimeConstantExpr).getStringValue() = val
135-
or
136-
exists(SsaExplicitUpdate v, Expr src |
137-
e = v.getAUse() and
138-
src = v.getDefiningExpr().(VariableAssign).getSource() and
139-
constantStringExpr(src, val)
140-
)
141-
}
142-
143-
/** An expression that always has the same string value. */
144-
private class ConstantStringExpr extends Expr {
145-
string value;
146-
147-
ConstantStringExpr() { constantStringExpr(this, value) }
148-
149-
/** Get the string value of this expression. */
150-
string getStringValue() { result = value }
151-
}
152-
153131
/**
154132
* A general configuration that is safe when enabled.
155133
*/

0 commit comments

Comments
 (0)