Skip to content

Commit bd3c6d5

Browse files
committed
Ruby: prune unusable summaries earlier
1 parent dc56f07 commit bd3c6d5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,19 @@ private predicate hasStoreSummary(
343343
SummarizedCallable callable, DataFlow::ContentSet contents, SummaryComponentStack input,
344344
SummaryComponentStack output
345345
) {
346-
callable.propagatesFlow(input, push(SummaryComponent::content(contents), output), true)
346+
callable.propagatesFlow(input, push(SummaryComponent::content(contents), output), true) and
347+
not isNonLocal(input.head()) and
348+
not isNonLocal(output.head())
347349
}
348350

349351
pragma[nomagic]
350352
private predicate hasLoadSummary(
351353
SummarizedCallable callable, DataFlow::ContentSet contents, SummaryComponentStack input,
352354
SummaryComponentStack output
353355
) {
354-
callable.propagatesFlow(push(SummaryComponent::content(contents), input), output, true)
356+
callable.propagatesFlow(push(SummaryComponent::content(contents), input), output, true) and
357+
not isNonLocal(input.head()) and
358+
not isNonLocal(output.head())
355359
}
356360

357361
pragma[nomagic]
@@ -362,6 +366,8 @@ private predicate hasLoadStoreSummary(
362366
callable
363367
.propagatesFlow(push(SummaryComponent::content(loadContents), input),
364368
push(SummaryComponent::content(storeContents), output), true) and
369+
not isNonLocal(input.head()) and
370+
not isNonLocal(output.head()) and
365371
callable != "Hash.[]" // Special-cased due to having a huge number of summaries
366372
}
367373

@@ -397,6 +403,8 @@ private predicate hasWithoutContentSummary(
397403
exists(DataFlow::ContentSet content |
398404
callable.propagatesFlow(push(SummaryComponent::withoutContent(content), input), output, true) and
399405
filter = getFilterFromWithoutContentStep(content) and
406+
not isNonLocal(input.head()) and
407+
not isNonLocal(output.head()) and
400408
input != output
401409
)
402410
}
@@ -433,10 +441,18 @@ private predicate hasWithContentSummary(
433441
exists(DataFlow::ContentSet content |
434442
callable.propagatesFlow(push(SummaryComponent::withContent(content), input), output, true) and
435443
filter = getFilterFromWithContentStep(content) and
444+
not isNonLocal(input.head()) and
445+
not isNonLocal(output.head()) and
436446
input != output
437447
)
438448
}
439449

450+
/**
451+
* Holds if the given component can't be evaluated by `evaluateSummaryComponentStackLocal`.
452+
*/
453+
pragma[nomagic]
454+
predicate isNonLocal(SummaryComponent component) { component = SC::content(_) }
455+
440456
/**
441457
* Gets a data flow node corresponding an argument or return value of `call`,
442458
* as specified by `component`.

0 commit comments

Comments
 (0)