From e87bf57bc5d45ce40347c2190d91aa0a0a9a8da4 Mon Sep 17 00:00:00 2001 From: Nick Rolfe Date: Thu, 29 Apr 2021 18:04:15 +0100 Subject: [PATCH] Avoid recursion in IPA construction --- ql/src/codeql_ruby/ast/internal/AST.qll | 16 +++++-- .../controlflow/graph/Cfg.expected | 48 +++++++++---------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/ql/src/codeql_ruby/ast/internal/AST.qll b/ql/src/codeql_ruby/ast/internal/AST.qll index 8b426edacc5..a7ad94ec652 100644 --- a/ql/src/codeql_ruby/ast/internal/AST.qll +++ b/ql/src/codeql_ruby/ast/internal/AST.qll @@ -119,13 +119,13 @@ private module Cached { THashSplatArgument(Generated::HashSplatArgument g) or THashSplatParameter(Generated::HashSplatParameter g) or THereDoc(Generated::HeredocBeginning g) or - TIdentifierMethodCall(Generated::Identifier g) { vcall(g) and not access(g, _) } or + TIdentifierMethodCall(Generated::Identifier g) { isIdentifierMethodCall(g) } or TIf(Generated::If g) or TIfModifierExpr(Generated::IfModifier g) or TImplicitSelf(Generated::AstNode g) { - exists(TIdentifierMethodCall(g)) + isIdentifierMethodCall(g) or - exists(TRegularMethodCall(g)) and + isRegularMethodCall(g) and not exists(g.(Generated::Call).getReceiver()) and not exists(g.(Generated::Call).getMethod().(Generated::ScopeResolution).getScope()) } or @@ -165,7 +165,7 @@ private module Cached { TRegexLiteral(Generated::Regex g) or TRegexMatchExpr(Generated::Binary g) { g instanceof @binary_equaltilde } or TRegularArrayLiteral(Generated::Array g) or - TRegularMethodCall(Generated::Call g) { not g.getMethod() instanceof Generated::Super } or + TRegularMethodCall(Generated::Call g) { isRegularMethodCall(g) } or TRegularStringLiteral(Generated::String g) or TRegularSuperCall(Generated::Call g) { g.getMethod() instanceof Generated::Super } or TRescueClause(Generated::Rescue g) or @@ -230,6 +230,14 @@ private module Cached { TWhileModifierExpr(Generated::WhileModifier g) or TYieldCall(Generated::Yield g) + private predicate isIdentifierMethodCall(Generated::Identifier g) { + vcall(g) and not access(g, _) + } + + private predicate isRegularMethodCall(Generated::Call g) { + not g.getMethod() instanceof Generated::Super + } + /** * Gets the underlying TreeSitter entity for a given AST node. This does not * include synthesized AST nodes, because they are not the primary AST node diff --git a/ql/test/library-tests/controlflow/graph/Cfg.expected b/ql/test/library-tests/controlflow/graph/Cfg.expected index f16443b7326..0eef0e36873 100644 --- a/ql/test/library-tests/controlflow/graph/Cfg.expected +++ b/ql/test/library-tests/controlflow/graph/Cfg.expected @@ -262,18 +262,18 @@ break_ensure.rb: #-----| true -> [ensure: return] then ... #-----| false -> [ensure: return] if ... -# 35| call to x -#-----| -> 0 - -# 35| [ensure: return] call to x -#-----| -> [ensure: return] 0 - # 35| self #-----| -> call to x # 35| [ensure: return] self #-----| -> [ensure: return] call to x +# 35| call to x +#-----| -> 0 + +# 35| [ensure: return] call to x +#-----| -> [ensure: return] 0 + # 35| 0 #-----| -> ... > ... @@ -429,12 +429,12 @@ case.rb: # 2| case ... #-----| -> self -# 2| call to x1 -#-----| -> when ... - # 2| self #-----| -> call to x1 +# 2| call to x1 +#-----| -> when ... + # 3| when ... #-----| -> 1 @@ -451,13 +451,13 @@ case.rb: # 3| if ... #-----| -> ( ... ) +# 3| self +#-----| -> call to x2 + # 3| call to x2 #-----| true -> then ... #-----| false -> if ... -# 3| self -#-----| -> call to x2 - # 3| then ... #-----| -> self @@ -881,12 +881,12 @@ cfg.rb: #-----| true -> "hello" #-----| false -> "bye" -# 60| call to b -#-----| -> 10 - # 60| self #-----| -> call to b +# 60| call to b +#-----| -> 10 + # 60| 10 #-----| -> ... < ... @@ -1330,21 +1330,21 @@ cfg.rb: # 109| #{...} #-----| -> self -# 109| call to table -#-----| -> #{...} - # 109| self #-----| -> call to table +# 109| call to table +#-----| -> #{...} + # 110| #{...} #-----| -> ( ... ) -# 110| call to type -#-----| -> #{...} - # 110| self #-----| -> call to type +# 110| call to type +#-----| -> #{...} + # 113| call to puts #-----| -> ... if ... @@ -1730,12 +1730,12 @@ cfg.rb: # 160| #{...} #-----| -> `cat "#{...}"` -# 160| call to __FILE__ -#-----| -> #{...} - # 160| self #-----| -> call to __FILE__ +# 160| call to __FILE__ +#-----| -> #{...} + # 162| ... = ... #-----| -> delimited_symbol