Skip to content

Commit aa2a49d

Browse files
committed
JS: Rewrite mayHaveStringValue to avoid misoptimization
1 parent 1f1ac72 commit aa2a49d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ module DataFlow {
118118
predicate accessesGlobal(string g) { globalVarRef(g).flowsTo(this) }
119119

120120
/** Holds if this node may evaluate to the string `s`, possibly through local data flow. */
121-
predicate mayHaveStringValue(string s) { getAPredecessor().mayHaveStringValue(s) }
121+
predicate mayHaveStringValue(string s) {
122+
getAPredecessor().mayHaveStringValue(s)
123+
or
124+
s = getStringValue()
125+
}
122126

123127
/** Gets the string value of this node, if it is a string literal or constant string concatenation. */
124128
string getStringValue() { result = asExpr().getStringValue() }
@@ -297,11 +301,6 @@ module DataFlow {
297301
/** Gets the expression or declaration this node corresponds to. */
298302
override AST::ValueNode getAstNode() { result = astNode }
299303

300-
override predicate mayHaveStringValue(string s) {
301-
Node.super.mayHaveStringValue(s) or
302-
astNode.(ConstantString).getStringValue() = s
303-
}
304-
305304
override BasicBlock getBasicBlock() { astNode = result.getANode() }
306305

307306
override predicate hasLocationInfo(

0 commit comments

Comments
 (0)