@@ -1009,7 +1009,7 @@ private predicate isUsedAsNonMatchObject(DataFlow::MethodCallNode call) {
10091009pragma [ inline]
10101010private predicate isUsedAsNumber ( DataFlow:: LocalSourceNode value ) {
10111011 any ( Comparison compare )
1012- .hasOperands ( value .getALocalUse ( ) .asExpr ( ) , any ( Expr e | e .analyze ( ) . getAType ( ) = TTNumber ( ) ) )
1012+ .hasOperands ( value .getALocalUse ( ) .asExpr ( ) , any ( Expr e | canBeNumber ( e .analyze ( ) ) ) )
10131013 or
10141014 value .flowsToExpr ( any ( ArithmeticExpr e ) .getAnOperand ( ) )
10151015 or
@@ -1024,20 +1024,30 @@ private predicate isUsedAsNumber(DataFlow::LocalSourceNode value) {
10241024 )
10251025}
10261026
1027+ bindingset [ node]
1028+ overlay [ global]
1029+ pragma [ inline_late]
1030+ private predicate canBeString ( DataFlow:: AnalyzedNode node ) { node .getAType ( ) = TTString ( ) }
1031+
1032+ bindingset [ node]
1033+ overlay [ global]
1034+ pragma [ inline_late]
1035+ private predicate canBeNumber ( DataFlow:: AnalyzedNode node ) { node .getAType ( ) = TTNumber ( ) }
1036+
10271037/**
10281038 * Holds if `source` may be interpreted as a regular expression.
10291039 */
10301040cached
10311041predicate isInterpretedAsRegExp ( DataFlow:: Node source ) {
10321042 Stages:: Taint:: ref ( ) and
1033- source . analyze ( ) . getAType ( ) = TTString ( ) and
1043+ canBeString ( source ) and
10341044 (
10351045 // The first argument to an invocation of `RegExp` (with or without `new`).
10361046 source = DataFlow:: globalVarRef ( "RegExp" ) .getAnInvocation ( ) .getArgument ( 0 )
10371047 or
10381048 // The argument of a call that coerces the argument to a regular expression.
10391049 exists ( DataFlow:: MethodCallNode mce , string methodName |
1040- mce .getReceiver ( ) . analyze ( ) . getAType ( ) = TTString ( ) and
1050+ canBeString ( mce .getReceiver ( ) ) and
10411051 mce .getMethodName ( ) = methodName and
10421052 not exists ( Function func | func = mce .getACallee ( ) |
10431053 not isNativeStringMethod ( func , methodName )
0 commit comments