Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4798a1a

Browse files
authored
Merge pull request #184 from github/cfg/singleton-method-abnormal
CFG: Add missing `propagatesAbnormal` overrides
2 parents b9b6ffe + c866f88 commit 4798a1a

3 files changed

Lines changed: 112 additions & 1 deletion

File tree

ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,8 @@ module Trees {
880880
}
881881

882882
private class LambdaTree extends BodyStmtTree, Lambda {
883+
final override predicate propagatesAbnormal(AstNode child) { none() }
884+
883885
/** Gets the `i`th child in the body of this block. */
884886
final override AstNode getBodyChild(int i, boolean rescuable) {
885887
result = this.getParameter(i) and rescuable = false
@@ -1158,6 +1160,8 @@ module Trees {
11581160
}
11591161

11601162
private class SingletonMethodTree extends BodyStmtTree, SingletonMethod {
1163+
final override predicate propagatesAbnormal(AstNode child) { none() }
1164+
11611165
/** Gets the `i`th child in the body of this block. */
11621166
final override AstNode getBodyChild(int i, boolean rescuable) {
11631167
result = this.getParameter(i) and rescuable = false

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

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,7 @@ raise.rb:
42534253
#-----| -> element
42544254

42554255
# 154| m14
4256-
#-----| -> exit raise.rb (normal)
4256+
#-----| -> m15
42574257

42584258
# 154| exit m14
42594259

@@ -4304,3 +4304,96 @@ raise.rb:
43044304

43054305
# 155| element
43064306
#-----| -> call to nil?
4307+
4308+
# 158| enter m15
4309+
#-----| -> self
4310+
4311+
# 158| m15
4312+
#-----| -> self
4313+
4314+
# 158| exit m15
4315+
4316+
# 158| exit m15 (normal)
4317+
#-----| -> exit m15
4318+
4319+
# 159| call to foo
4320+
#-----| -> exit m15 (normal)
4321+
4322+
# 159| self
4323+
#-----| -> do ... end
4324+
4325+
# 159| enter do ... end
4326+
#-----| -> self
4327+
4328+
# 159| do ... end
4329+
#-----| -> call to foo
4330+
4331+
# 159| exit do ... end
4332+
4333+
# 159| exit do ... end (normal)
4334+
#-----| -> exit do ... end
4335+
4336+
# 160| call to bar
4337+
#-----| -> exit do ... end (normal)
4338+
4339+
# 160| self
4340+
#-----| -> -> { ... }
4341+
4342+
# 160| enter -> { ... }
4343+
#-----| -> x
4344+
4345+
# 160| -> { ... }
4346+
#-----| -> call to bar
4347+
4348+
# 160| exit -> { ... }
4349+
4350+
# 160| exit -> { ... } (abnormal)
4351+
#-----| -> exit -> { ... }
4352+
4353+
# 160| exit -> { ... } (normal)
4354+
#-----| -> exit -> { ... }
4355+
4356+
# 160| x
4357+
#-----| -> x
4358+
4359+
# 161| call to raise
4360+
#-----| raise -> exit -> { ... } (abnormal)
4361+
4362+
# 161| ... unless ...
4363+
#-----| -> exit -> { ... } (normal)
4364+
4365+
# 161| self
4366+
#-----| -> ""
4367+
4368+
# 161| ""
4369+
#-----| -> call to raise
4370+
4371+
# 161| x
4372+
#-----| true -> ... unless ...
4373+
#-----| false -> self
4374+
4375+
# 166| C
4376+
#-----| -> exit raise.rb (normal)
4377+
4378+
# 167| enter m
4379+
#-----| -> self
4380+
4381+
# 167| m
4382+
#-----| -> C
4383+
4384+
# 167| exit m
4385+
4386+
# 167| exit m (abnormal)
4387+
#-----| -> exit m
4388+
4389+
# 167| self
4390+
#-----| -> m
4391+
4392+
# 168| call to raise
4393+
#-----| raise -> exit m (abnormal)
4394+
4395+
# 168| self
4396+
#-----| -> ""
4397+
4398+
# 168| ""
4399+
#-----| -> call to raise

ql/test/library-tests/controlflow/graph/raise.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,17 @@ def m13
154154
def m14 element
155155
element.each { |elem| raise "" if element.nil? }
156156
end
157+
158+
def m15
159+
foo do
160+
bar ->(x) do
161+
raise "" unless x
162+
end
163+
end
164+
end
165+
166+
class C
167+
def self.m()
168+
raise ""
169+
end
170+
end

0 commit comments

Comments
 (0)