File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
test/query-tests/Security/CWE-020 Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,16 @@ class UnsafeIndexOfComparison extends EqualityTest {
139139 not test .isInclusive ( ) and
140140 value = - 1
141141 )
142+ ) and
143+ // Check for indexOf being <0, or <=-1
144+ not exists ( RelationalComparison test |
145+ test .getLesserOperand ( ) = indexOf .getAnEquivalentIndexOfCall ( ) .getAUse ( ) and
146+ exists ( int value | value = test .getGreaterOperand ( ) .getIntValue ( ) |
147+ value < 0
148+ or
149+ not test .isInclusive ( ) and
150+ value = 0
151+ )
142152 )
143153 }
144154
Original file line number Diff line number Diff line change @@ -79,3 +79,13 @@ function withIndexOfCheckBad(x, y) {
7979function plus ( x , y ) {
8080 return x . indexOf ( "." + y ) === x . length - ( y . length + 1 ) ; // NOT OK
8181}
82+
83+ function withIndexOfCheckLower ( x , y ) {
84+ let index = x . indexOf ( y ) ;
85+ return ! ( index < 0 ) && index === x . length - y . length - 1 ; // OK
86+ }
87+
88+ function withIndexOfCheckLowerEq ( x , y ) {
89+ let index = x . indexOf ( y ) ;
90+ return ! ( index <= - 1 ) && index === x . length - y . length - 1 ; // OK
91+ }
You can’t perform that action at this time.
0 commit comments