Skip to content

Commit ce3b359

Browse files
committed
Ruby: Fix CFG for nodes that may raise
1 parent 6d2d965 commit ce3b359

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

ruby/ql/lib/codeql/ruby/controlflow/internal/Completion.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ private predicate mayRaise(Call c) { c = getARescuableBodyChild() }
9090

9191
/** A completion of a statement or an expression. */
9292
abstract class Completion extends TCompletion {
93-
private predicate isValidForSpecific(AstNode n) {
94-
exists(AstNode other | n = other.getDesugared() and this.isValidForSpecific(other))
95-
or
93+
private predicate isValidForSpecific0(AstNode n) {
9694
this = n.(NonReturningCall).getACompletion()
9795
or
9896
completionIsValidForStmt(n, this)
@@ -110,12 +108,19 @@ abstract class Completion extends TCompletion {
110108
or
111109
n = any(RescueModifierExpr parent).getBody() and
112110
this = [TSimpleCompletion().(TCompletion), TRaiseCompletion()]
111+
}
112+
113+
private predicate isValidForSpecific(AstNode n) {
114+
this.isValidForSpecific0(n)
115+
or
116+
exists(AstNode other | n = other.getDesugared() and this.isValidForSpecific(other))
113117
or
114118
mayRaise(n) and
115119
(
116120
this = TRaiseCompletion()
117121
or
118-
this = TSimpleCompletion() and not n instanceof NonReturningCall
122+
not any(Completion c).isValidForSpecific0(n) and
123+
this = TSimpleCompletion()
119124
)
120125
}
121126

ruby/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6953,11 +6953,6 @@ raise.rb:
69536953
#-----| true -> [true] ... || ...
69546954
#-----| false -> b2
69556955

6956-
# 174| ... || ...
6957-
#-----| true -> 1
6958-
#-----| false -> 2
6959-
#-----| raise -> ExceptionA
6960-
69616956
# 174| [false] ... || ...
69626957
#-----| false -> 2
69636958
#-----| raise -> ExceptionA
@@ -6971,7 +6966,6 @@ raise.rb:
69716966

69726967
# 174| ... == ...
69736968
#-----| false -> [false] ... || ...
6974-
#-----| -> ... || ...
69756969
#-----| true -> [true] ... || ...
69766970
#-----| raise -> ExceptionA
69776971

ruby/ql/test/library-tests/controlflow/graph/Nodes.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ positionalArguments
367367
| raise.rb:160:5:162:7 | call to bar | raise.rb:160:9:162:7 | -> { ... } |
368368
| raise.rb:161:7:161:14 | call to raise | raise.rb:161:13:161:14 | "" |
369369
| raise.rb:168:5:168:12 | call to raise | raise.rb:168:11:168:12 | "" |
370-
| raise.rb:174:8:174:23 | ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
371370
| raise.rb:174:8:174:23 | [false] ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
372371
| raise.rb:174:8:174:23 | [true] ... \|\| ... | raise.rb:174:14:174:23 | ... == ... |
373372
| raise.rb:174:14:174:23 | ... == ... | raise.rb:174:20:174:23 | true |

0 commit comments

Comments
 (0)