Skip to content

Commit ae60b0a

Browse files
committed
Ruby: ensure pruning works with startInContent
1 parent f1de5a2 commit ae60b0a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

ruby/ql/lib/codeql/ruby/typetracking/TypeTracker.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,15 @@ module StepSummary {
220220

221221
private newtype TTypeTracker =
222222
MkTypeTracker(Boolean hasCall, OptionalTypeTrackerContent content) {
223-
content = noContent() or basicStoreStep(_, _, content)
223+
content = noContent()
224+
or
225+
// Restrict `content` to those that might eventually match a load.
226+
// We can't rely on `basicStoreStep` since `startInContent` might be used with
227+
// a content that has no corresponding store.
228+
exists(TypeTrackerContent loadContents |
229+
basicLoadStep(_, _, loadContents) and
230+
compatibleContents(content, loadContents)
231+
)
224232
}
225233

226234
/**
@@ -376,7 +384,13 @@ module TypeTracker {
376384

377385
private newtype TTypeBackTracker =
378386
MkTypeBackTracker(Boolean hasReturn, OptionalTypeTrackerContent content) {
379-
content = noContent() or basicLoadStep(_, _, content)
387+
content = noContent()
388+
or
389+
// As in MkTypeTracker, restrict `content` to those that might eventually match a store.
390+
exists(TypeTrackerContent storeContent |
391+
basicStoreStep(_, _, storeContent) and
392+
compatibleContents(storeContent, content)
393+
)
380394
}
381395

382396
/**

ruby/ql/test/library-tests/dataflow/type-tracker/TypeTracker.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ track
156156
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps | type_tracker.rb:40:5:40:12 | ...[...] |
157157
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps | type_tracker.rb:44:5:44:13 | ...[...] |
158158
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps | type_tracker.rb:52:5:52:13 | ...[...] |
159-
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content attribute [] | type_tracker.rb:39:5:39:9 | [post] array |
160-
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content attribute [] | type_tracker.rb:43:5:43:10 | [post] array2 |
161-
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content attribute [] | type_tracker.rb:47:5:47:10 | [post] array3 |
162-
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content attribute [] | type_tracker.rb:51:5:51:10 | [post] array4 |
163159
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content element | type_tracker.rb:38:13:38:25 | call to [] |
164160
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content element | type_tracker.rb:50:14:50:26 | call to [] |
165161
| type_tracker.rb:34:18:34:20 | obj | type tracker with call steps with content element 0 or unknown | type_tracker.rb:35:11:35:15 | call to [] |
@@ -173,10 +169,6 @@ track
173169
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps | type_tracker.rb:40:5:40:12 | ...[...] |
174170
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps | type_tracker.rb:44:5:44:13 | ...[...] |
175171
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps | type_tracker.rb:52:5:52:13 | ...[...] |
176-
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content attribute [] | type_tracker.rb:39:5:39:9 | [post] array |
177-
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content attribute [] | type_tracker.rb:43:5:43:10 | [post] array2 |
178-
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content attribute [] | type_tracker.rb:47:5:47:10 | [post] array3 |
179-
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content attribute [] | type_tracker.rb:51:5:51:10 | [post] array4 |
180172
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content element | type_tracker.rb:38:13:38:25 | call to [] |
181173
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content element | type_tracker.rb:50:14:50:26 | call to [] |
182174
| type_tracker.rb:34:18:34:20 | obj | type tracker without call steps with content element 0 or unknown | type_tracker.rb:35:11:35:15 | call to [] |

0 commit comments

Comments
 (0)