@@ -36,10 +36,17 @@ class IndexOfCall extends DataFlow::MethodCallNode {
3636 result .getArgument ( 0 ) .getALocalSource ( ) = this .getArgument ( 0 ) .getALocalSource ( ) and
3737 result .getMethodName ( ) = this .getMethodName ( )
3838 }
39+
40+ /**
41+ * Gets an expression that refers to the return value of this call.
42+ */
43+ Expr getAUse ( ) {
44+ this .flowsToExpr ( result )
45+ }
3946}
4047
4148/**
42- * Gets a source of the given string value.
49+ * Gets a source of the given string value, or one of its operands if it is a concatenation .
4350 */
4451DataFlow:: SourceNode getStringSource ( DataFlow:: Node node ) {
4552 result = node .getALocalSource ( )
@@ -65,7 +72,7 @@ class LiteralLengthExpr extends DotExpr {
6572}
6673
6774/**
68- * Holds if `node ` is derived from the length of the given `indexOf`-operand.
75+ * Holds if `length ` is derived from the length of the given `indexOf`-operand.
6976 */
7077predicate isDerivedFromLength ( DataFlow:: Node length , DataFlow:: Node operand ) {
7178 exists ( IndexOfCall call | operand = call .getAnOperand ( ) |
@@ -84,9 +91,7 @@ predicate isDerivedFromLength(DataFlow::Node length, DataFlow::Node operand) {
8491 length = lengthExpr .flow ( ) )
8592 )
8693 or
87- exists ( DataFlow:: Node mid |
88- isDerivedFromLength ( mid , operand ) and
89- length = mid .getASuccessor ( ) )
94+ isDerivedFromLength ( length .getAPredecessor ( ) , operand )
9095 or
9196 exists ( SubExpr sub |
9297 isDerivedFromLength ( sub .getAnOperand ( ) .flow ( ) , operand ) and
@@ -101,7 +106,7 @@ class UnsafeIndexOfComparison extends EqualityTest {
101106 DataFlow:: Node testedValue ;
102107
103108 UnsafeIndexOfComparison ( ) {
104- hasOperands ( indexOf .asExpr ( ) , testedValue .asExpr ( ) ) and
109+ hasOperands ( indexOf .getAUse ( ) , testedValue .asExpr ( ) ) and
105110 isDerivedFromLength ( testedValue , indexOf .getReceiver ( ) ) and
106111 isDerivedFromLength ( testedValue , indexOf .getArgument ( 0 ) ) and
107112
@@ -118,13 +123,13 @@ class UnsafeIndexOfComparison extends EqualityTest {
118123
119124 // Check for indexOf being -1
120125 not exists ( EqualityTest test , Expr minusOne |
121- test .hasOperands ( indexOf .getAnEquivalentIndexOfCall ( ) .asExpr ( ) , minusOne ) and
126+ test .hasOperands ( indexOf .getAnEquivalentIndexOfCall ( ) .getAUse ( ) , minusOne ) and
122127 minusOne .getIntValue ( ) = - 1
123128 ) and
124129
125130 // Check for indexOf being >1, or >=0, etc
126131 not exists ( RelationalComparison test |
127- test .getGreaterOperand ( ) = indexOf .getAnEquivalentIndexOfCall ( ) .asExpr ( ) and
132+ test .getGreaterOperand ( ) = indexOf .getAnEquivalentIndexOfCall ( ) .getAUse ( ) and
128133 exists ( int value | value = test .getLesserOperand ( ) .getIntValue ( ) |
129134 value >= 0
130135 or
0 commit comments