Skip to content

Commit 2b41f62

Browse files
author
Esben Sparre Andreasen
committed
JS: introduce RelationalComparison.isInclucive
1 parent 20b48a2 commit 2b41f62

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,14 @@ class RelationalComparison extends Comparison {
15451545
Expr getGreaterOperand() {
15461546
result = getAnOperand() and result != getLesserOperand()
15471547
}
1548+
1549+
/**
1550+
* Holds if this is a comparison with `<=` or `>=`.
1551+
*/
1552+
predicate isInclusive() {
1553+
this instanceof LEExpr or
1554+
this instanceof GEExpr
1555+
}
15481556
}
15491557

15501558
/** A (pre or post) increment expression. */

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,6 @@ module TaintTracking {
643643

644644
}
645645

646-
/**
647-
* A less-than or greater-than expression
648-
*/
649-
private class ExclusiveRelationalComparison extends RelationalComparison {
650-
ExclusiveRelationalComparison() {
651-
this instanceof LTExpr or
652-
this instanceof GTExpr
653-
}
654-
}
655-
656646
/**
657647
* A check of the form `if(whitelist.indexOf(x) >= 0)`, which sanitizes `x` in its "then" branch.
658648
*
@@ -671,17 +661,17 @@ module TaintTracking {
671661
polarity = true and
672662
greater = indexOf and
673663
(
674-
lesser.getIntValue() = 0
664+
lesser.getIntValue() >= 0
675665
or
676-
lesser.getIntValue() = -1 and astNode instanceof ExclusiveRelationalComparison
666+
lesser.getIntValue() = -1 and not astNode.isInclusive()
677667
)
678668
or
679669
polarity = false and
680670
lesser = indexOf and
681671
(
682672
greater.getIntValue() = -1
683673
or
684-
greater.getIntValue() = 0 and astNode instanceof ExclusiveRelationalComparison
674+
greater.getIntValue() = 0 and not astNode.isInclusive()
685675
)
686676
)
687677
}

0 commit comments

Comments
 (0)