@@ -1016,7 +1016,7 @@ overlay[global]
10161016pragma [ inline]
10171017private predicate isUsedAsNumber ( DataFlow:: LocalSourceNode value ) {
10181018 any ( Comparison compare )
1019- .hasOperands ( value .getALocalUse ( ) .asExpr ( ) , any ( Expr e | e .analyze ( ) . getAType ( ) = TTNumber ( ) ) )
1019+ .hasOperands ( value .getALocalUse ( ) .asExpr ( ) , any ( Expr e | canBeNumber ( e .analyze ( ) ) ) )
10201020 or
10211021 value .flowsToExpr ( any ( ArithmeticExpr e ) .getAnOperand ( ) )
10221022 or
@@ -1031,21 +1031,31 @@ private predicate isUsedAsNumber(DataFlow::LocalSourceNode value) {
10311031 )
10321032}
10331033
1034+ bindingset [ node]
1035+ overlay [ global]
1036+ pragma [ inline_late]
1037+ private predicate canBeString ( DataFlow:: AnalyzedNode node ) { node .getAType ( ) = TTString ( ) }
1038+
1039+ bindingset [ node]
1040+ overlay [ global]
1041+ pragma [ inline_late]
1042+ private predicate canBeNumber ( DataFlow:: AnalyzedNode node ) { node .getAType ( ) = TTNumber ( ) }
1043+
10341044/**
10351045 * Holds if `source` may be interpreted as a regular expression.
10361046 */
10371047overlay [ global]
10381048cached
10391049predicate isInterpretedAsRegExp ( DataFlow:: Node source ) {
10401050 Stages:: Taint:: ref ( ) and
1041- source . analyze ( ) . getAType ( ) = TTString ( ) and
1051+ canBeString ( source ) and
10421052 (
10431053 // The first argument to an invocation of `RegExp` (with or without `new`).
10441054 source = DataFlow:: globalVarRef ( "RegExp" ) .getAnInvocation ( ) .getArgument ( 0 )
10451055 or
10461056 // The argument of a call that coerces the argument to a regular expression.
10471057 exists ( DataFlow:: MethodCallNode mce , string methodName |
1048- mce .getReceiver ( ) . analyze ( ) . getAType ( ) = TTString ( ) and
1058+ canBeString ( mce .getReceiver ( ) ) and
10491059 mce .getMethodName ( ) = methodName and
10501060 not exists ( Function func | func = mce .getACallee ( ) |
10511061 not isNativeStringMethod ( func , methodName )
0 commit comments