Skip to content

Commit 9f2eb84

Browse files
authored
Merge pull request github#4624 from erik-krogh/concatFix
Approved by asgerf
2 parents cb77e46 + 9137759 commit 9f2eb84

File tree

1 file changed

+14
-5
lines changed
  • javascript/ql/src/semmle/javascript

1 file changed

+14
-5
lines changed

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,17 +1603,26 @@ private predicate hasAllConstantLeafs(AddExpr add) {
16031603
private string getConcatenatedString(Expr add) {
16041604
result = getConcatenatedString(add.getUnderlyingValue())
16051605
or
1606-
not add = getAnAddOperand(any(AddExpr parent | hasAllConstantLeafs(parent))) and
1607-
hasAllConstantLeafs(add) and
16081606
result =
16091607
strictconcat(Expr leaf |
1610-
leaf = getAnAddOperand*(add)
1608+
leaf = getAnAddOperand*(add.(SmallConcatRoot))
16111609
|
16121610
getConstantString(leaf)
16131611
order by
16141612
leaf.getLocation().getStartLine(), leaf.getLocation().getStartColumn()
1615-
) and
1616-
result.length() < 1000 * 1000
1613+
)
1614+
}
1615+
1616+
/**
1617+
* An expr that is the root of a string concatenation of constant parts,
1618+
* and the length of the resulting concatenation is less than 1 million chars.
1619+
*/
1620+
private class SmallConcatRoot extends Expr {
1621+
SmallConcatRoot() {
1622+
not this = getAnAddOperand(any(AddExpr parent | hasAllConstantLeafs(parent))) and
1623+
hasAllConstantLeafs(this) and
1624+
sum(Expr leaf | leaf = getAnAddOperand*(this) | getConstantString(leaf).length()) < 1000 * 1000
1625+
}
16171626
}
16181627

16191628
/**

0 commit comments

Comments
 (0)