Skip to content

Commit

Permalink
Ruby: Fix CFG for nodes that may raise
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Apr 4, 2024
1 parent 6d2d965 commit ce3b359
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
13 changes: 9 additions & 4 deletions ruby/ql/lib/codeql/ruby/controlflow/internal/Completion.qll
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ private predicate mayRaise(Call c) { c = getARescuableBodyChild() }

/** A completion of a statement or an expression. */
abstract class Completion extends TCompletion {
private predicate isValidForSpecific(AstNode n) {
exists(AstNode other | n = other.getDesugared() and this.isValidForSpecific(other))
or
private predicate isValidForSpecific0(AstNode n) {
this = n.(NonReturningCall).getACompletion()
or
completionIsValidForStmt(n, this)
Expand All @@ -110,12 +108,19 @@ abstract class Completion extends TCompletion {
or
n = any(RescueModifierExpr parent).getBody() and
this = [TSimpleCompletion().(TCompletion), TRaiseCompletion()]
}

private predicate isValidForSpecific(AstNode n) {
this.isValidForSpecific0(n)
or
exists(AstNode other | n = other.getDesugared() and this.isValidForSpecific(other))
or
mayRaise(n) and
(
this = TRaiseCompletion()
or
this = TSimpleCompletion() and not n instanceof NonReturningCall
not any(Completion c).isValidForSpecific0(n) and
this = TSimpleCompletion()
)
}

Expand Down
6 changes: 0 additions & 6 deletions ruby/ql/test/library-tests/controlflow/graph/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -6953,11 +6953,6 @@ raise.rb:
#-----| true -> [true] ... || ...
#-----| false -> b2

# 174| ... || ...
#-----| true -> 1
#-----| false -> 2
#-----| raise -> ExceptionA

# 174| [false] ... || ...
#-----| false -> 2
#-----| raise -> ExceptionA
Expand All @@ -6971,7 +6966,6 @@ raise.rb:

# 174| ... == ...
#-----| false -> [false] ... || ...
#-----| -> ... || ...
#-----| true -> [true] ... || ...
#-----| raise -> ExceptionA

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ positionalArguments
| raise.rb:160:5:162:7 | call to bar | raise.rb:160:9:162:7 | -> { ... } |
| raise.rb:161:7:161:14 | call to raise | raise.rb:161:13:161:14 | "" |
| raise.rb:168:5:168:12 | call to raise | raise.rb:168:11:168:12 | "" |
| raise.rb:174:8:174:23 | ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
| raise.rb:174:8:174:23 | [false] ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
| raise.rb:174:8:174:23 | [true] ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
| raise.rb:174:14:174:23 | ... == ... | raise.rb:174:20:174:23 | true |
Expand Down

0 comments on commit ce3b359

Please sign in to comment.