|
| 1 | +/** Provides classes and predicates for defining flow summaries. */ |
| 2 | + |
| 3 | +private import rust |
| 4 | +private import internal.FlowSummaryImpl as Impl |
| 5 | +private import codeql.rust.elements.internal.CallExprBaseImpl::Impl as CallExprBaseImpl |
| 6 | + |
| 7 | +// import all instances below |
| 8 | +private module Summaries { |
| 9 | + private import codeql.rust.Frameworks |
| 10 | + |
| 11 | + // TODO: Use models-as-data when it's available |
| 12 | + private class UnwrapSummary extends SummarizedCallable::Range { |
| 13 | + UnwrapSummary() { this = "lang:core::_::<crate::option::Option>::unwrap" } |
| 14 | + |
| 15 | + override predicate propagatesFlow(string input, string output, boolean preservesValue) { |
| 16 | + input = "Argument[self].Variant[crate::option::Option::Some(0)]" and |
| 17 | + output = "ReturnValue" and |
| 18 | + preservesValue = true |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +/** Provides the `Range` class used to define the extent of `LibraryCallable`. */ |
| 24 | +module LibraryCallable { |
| 25 | + /** A callable defined in library code, identified by a unique string. */ |
| 26 | + abstract class Range extends string { |
| 27 | + bindingset[this] |
| 28 | + Range() { any() } |
| 29 | + |
| 30 | + /** Gets a call to this library callable. */ |
| 31 | + CallExprBase getACall() { |
| 32 | + exists(Resolvable r, string crate | |
| 33 | + r = CallExprBaseImpl::getCallResolvable(result) and |
| 34 | + this = crate + r.getResolvedPath() |
| 35 | + | |
| 36 | + crate = r.getResolvedCrateOrigin() + "::_::" |
| 37 | + or |
| 38 | + not r.hasResolvedCrateOrigin() and |
| 39 | + crate = "" |
| 40 | + ) |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +final class LibraryCallable = LibraryCallable::Range; |
| 46 | + |
| 47 | +/** Provides the `Range` class used to define the extent of `SummarizedCallable`. */ |
| 48 | +module SummarizedCallable { |
| 49 | + /** A callable with a flow summary, identified by a unique string. */ |
| 50 | + abstract class Range extends LibraryCallable::Range, Impl::Public::SummarizedCallable { |
| 51 | + bindingset[this] |
| 52 | + Range() { any() } |
| 53 | + |
| 54 | + override predicate propagatesFlow( |
| 55 | + string input, string output, boolean preservesValue, string model |
| 56 | + ) { |
| 57 | + this.propagatesFlow(input, output, preservesValue) and model = "" |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Holds if data may flow from `input` to `output` through this callable. |
| 62 | + * |
| 63 | + * `preservesValue` indicates whether this is a value-preserving step or a taint-step. |
| 64 | + */ |
| 65 | + abstract predicate propagatesFlow(string input, string output, boolean preservesValue); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +final class SummarizedCallable = SummarizedCallable::Range; |
0 commit comments