Skip to content

Commit 6b459de

Browse files
authored
Merge pull request #717 from xiemaisi/js/fix-incorrect-suffix-check-performance
Approved by asger-semmle
2 parents 114740c + a9844b2 commit 6b459de

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

javascript/ql/src/Security/CWE-020/IncorrectSuffixCheck.ql

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,21 @@ predicate isDerivedFromLength(DataFlow::Node length, DataFlow::Node operand) {
7878
exists (IndexOfCall call | operand = call.getAnOperand() |
7979
length = getStringSource(operand).getAPropertyRead("length")
8080
or
81-
// Find a literal length with the same string constant
82-
exists (LiteralLengthExpr lengthExpr |
83-
lengthExpr.getContainer() = call.getContainer() and
84-
lengthExpr.getBaseValue() = operand.asExpr().getStringValue() and
85-
length = lengthExpr.flow())
86-
or
87-
// Find an integer constants that equals the length of string constant
88-
exists (Expr lengthExpr |
89-
lengthExpr.getContainer() = call.getContainer() and
90-
lengthExpr.getIntValue() = operand.asExpr().getStringValue().length() and
91-
length = lengthExpr.flow())
81+
exists (string val | val = operand.asExpr().getStringValue() |
82+
// Find a literal length with the same string constant
83+
exists (LiteralLengthExpr lengthExpr |
84+
lengthExpr.getContainer() = call.getContainer() and
85+
lengthExpr.getBaseValue() = val and
86+
length = lengthExpr.flow()
87+
)
88+
or
89+
// Find an integer constant that equals the length of string constant
90+
exists (Expr lengthExpr |
91+
lengthExpr.getContainer() = call.getContainer() and
92+
lengthExpr.getIntValue() = val.length() and
93+
length = lengthExpr.flow()
94+
)
95+
)
9296
)
9397
or
9498
isDerivedFromLength(length.getAPredecessor(), operand)

0 commit comments

Comments
 (0)