Skip to content

Commit 29cbc3f

Browse files
committed
Rust: Adapt to changes in FlowSummaryImpl
1 parent eeaca61 commit 29cbc3f

File tree

5 files changed

+76
-60
lines changed

5 files changed

+76
-60
lines changed

rust/ql/lib/codeql/rust/dataflow/FlowSummary.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ module SummarizedCallable {
1717
Range() { any() }
1818

1919
override predicate propagatesFlow(
20-
string input, string output, boolean preservesValue, string model
20+
string input, string output, boolean preservesValue, Provenance p, boolean isExact,
21+
string model
2122
) {
22-
this.propagatesFlow(input, output, preservesValue) and model = ""
23+
this.propagatesFlow(input, output, preservesValue) and
24+
p = "manual" and
25+
isExact = true and
26+
model = "QL"
2327
}
2428

2529
/**
@@ -31,6 +35,6 @@ module SummarizedCallable {
3135
}
3236
}
3337

34-
final class SummarizedCallable = SummarizedCallable::Range;
38+
final class SummarizedCallable = Impl::Public::RelevantSummarizedCallable;
3539

3640
final class Provenance = Impl::Public::Provenance;

rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module Input implements InputSig<Location, RustDataFlow> {
3030

3131
class SummarizedCallableBase = Function;
3232

33+
predicate callableFromSource(SummarizedCallableBase c) { c.fromSource() }
34+
3335
abstract private class SourceSinkBase extends AstNode {
3436
/** Gets the associated call. */
3537
abstract Call getCall();

rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -111,60 +111,35 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
111111
)
112112
}
113113

114-
private predicate summaryModel(
115-
Function f, string input, string output, string kind, Provenance provenance, boolean isInherited,
116-
QlBuiltins::ExtensionId madId
117-
) {
118-
exists(string path, Function f0 |
119-
summaryModel(path, input, output, kind, provenance, madId) and
120-
f0.getCanonicalPath() = path
121-
|
122-
f = f0 and
123-
isInherited = false
124-
or
125-
f.implements(f0) and
126-
isInherited = true
127-
)
128-
}
129-
130-
private predicate summaryModelRelevant(
131-
Function f, string input, string output, string kind, Provenance provenance, boolean isInherited,
132-
QlBuiltins::ExtensionId madId
133-
) {
134-
summaryModel(f, input, output, kind, provenance, isInherited, madId) and
135-
// Only apply generated or inherited models to functions in library code and
136-
// when no strictly better model exists
137-
if provenance.isGenerated() or isInherited = true
138-
then
139-
not f.fromSource() and
140-
not exists(Provenance other | summaryModel(f, _, _, _, other, false, _) |
141-
provenance.isGenerated() and other.isManual()
114+
private class SummarizedCallableFromModel extends SummarizedCallable::Range {
115+
string input_;
116+
string output_;
117+
string kind;
118+
Provenance p_;
119+
boolean isExact_;
120+
QlBuiltins::ExtensionId madId;
121+
122+
SummarizedCallableFromModel() {
123+
exists(string path, Function f |
124+
summaryModel(path, input_, output_, kind, p_, madId) and
125+
f.getCanonicalPath() = path
126+
|
127+
this = f and isExact_ = true
142128
or
143-
provenance = other and isInherited = true
129+
this.implements(f) and
130+
isExact_ = false
144131
)
145-
else any()
146-
}
147-
148-
private class SummarizedCallableFromModel extends SummarizedCallable::Range {
149-
SummarizedCallableFromModel() { summaryModelRelevant(this, _, _, _, _, _, _) }
150-
151-
override predicate hasProvenance(Provenance provenance) {
152-
summaryModelRelevant(this, _, _, _, provenance, _, _)
153132
}
154133

155134
override predicate propagatesFlow(
156-
string input, string output, boolean preservesValue, string model
135+
string input, string output, boolean preservesValue, Provenance p, boolean isExact, string model
157136
) {
158-
exists(string kind, QlBuiltins::ExtensionId madId |
159-
summaryModelRelevant(this, input, output, kind, _, _, madId) and
160-
model = "MaD:" + madId.toString()
161-
|
162-
kind = "value" and
163-
preservesValue = true
164-
or
165-
kind = "taint" and
166-
preservesValue = false
167-
)
137+
input = input_ and
138+
output = output_ and
139+
(if kind = "value" then preservesValue = true else preservesValue = false) and
140+
p = p_ and
141+
isExact = isExact_ and
142+
model = "MaD:" + madId.toString()
168143
}
169144
}
170145

@@ -211,7 +186,7 @@ private module Debug {
211186
private predicate relevantManualModel(SummarizedCallableImpl sc, string can) {
212187
exists(Provenance manual |
213188
can = sc.getCanonicalPath() and
214-
summaryModelRelevant(sc, _, _, _, manual, false, _) and
189+
sc.(SummarizedCallableFromModel).propagatesFlow(_, _, _, manual, true, _) and
215190
manual.isManual()
216191
)
217192
}
@@ -221,7 +196,7 @@ private module Debug {
221196
) {
222197
exists(RustDataFlow::ParameterPosition pos, TypeMention tm |
223198
relevantManualModel(sc, can) and
224-
sc.propagatesFlow(input, _, _, _) and
199+
sc.propagatesFlow(input, _, _, _, _, _) and
225200
input.head() = SummaryComponent::argument(pos) and
226201
p = pos.getParameterIn(sc.getParamList()) and
227202
tm.resolveType() instanceof RefType and
@@ -238,7 +213,7 @@ private module Debug {
238213
) {
239214
exists(TypeMention tm |
240215
relevantManualModel(sc, can) and
241-
sc.propagatesFlow(_, output, _, _) and
216+
sc.propagatesFlow(_, output, _, _, _, _) and
242217
tm.resolveType() instanceof RefType and
243218
output.head() = SummaryComponent::return(_) and
244219
not output.tail().head() =

rust/ql/test/library-tests/dataflow/models/models.expected

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,44 @@ subpaths
679679
| main.rs:219:19:219:19 | s | main.rs:218:14:218:14 | ... | main.rs:218:17:218:42 | if ... {...} else {...} | main.rs:219:13:219:23 | apply(...) |
680680
testFailures
681681
invalidSpecComponent
682+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes.rs:953:5:955:5 | fn from | Argument[0].Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] | Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] |
683+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes.rs:959:5:961:5 | fn from | Argument[0].Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] | Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] |
684+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes.rs:965:5:996:5 | fn from | Argument[0].Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] | Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] |
685+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes.rs:1000:5:1027:5 | fn from | Argument[0].Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] | Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] |
686+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes.rs:1053:5:1055:5 | fn from | Argument[0].Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] | Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] |
687+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bytes-1.10.1/src/bytes_mut.rs:1274:5:1276:5 | fn from | Argument[0].Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] | Field[hyper::ext::h1_reason_phrase::ReasonPhrase(0)] |
688+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/mio-1.0.4/src/token.rs:135:5:137:5 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
689+
| file:///Users/hvitved/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.45.1/src/runtime/scheduler/multi_thread/idle.rs:218:5:220:5 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
690+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1613:5:1652:5 | fn into_pin | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
691+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed/convert.rs:47:5:60:5 | fn from | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
692+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ascii/ascii_char.rs:560:19:560:21 | fn from | Argument[0].Field[actix_http::ws::proto::CloseCode::Other(0)] | Field[actix_http::ws::proto::CloseCode::Other(0)] |
693+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/char/mod.rs:330:5:333:5 | fn next | Argument[self].Field[0].Field[core::char::EscapeDebugInner::Char(0)] | Field[core::char::EscapeDebugInner::Char(0)] |
694+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/char/mod.rs:330:5:333:5 | fn next | Argument[self].Field[core::char::EscapeDebug(0)].Field[core::char::EscapeDebugInner::Char(0)] | Field[core::char::EscapeDebugInner::Char(0)] |
695+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/num.rs:87:20:87:22 | fn from | Argument[0].Field[actix_http::ws::proto::CloseCode::Other(0)] | Field[actix_http::ws::proto::CloseCode::Other(0)] |
696+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/num.rs:91:20:91:24 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
697+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/num.rs:100:12:100:20 | fn from | Argument[0].Field[actix_http::ws::proto::CloseCode::Other(0)] | Field[actix_http::ws::proto::CloseCode::Other(0)] |
698+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/num.rs:104:12:104:22 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
699+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/num.rs:140:12:140:23 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
700+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/flatten.rs:26:5:32:5 | fn into_parts | ReturnValue.Field[2] | Field[2] |
701+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/sources/repeat_n.rs:82:12:83:9 | fn clone | Argument[self].Field[core::iter::sources::repeat_n::RepeatN::count] | Field[core::iter::sources::repeat_n::RepeatN::count] |
702+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/sources/repeat_n.rs:82:12:83:9 | fn clone | ReturnValue.Field[core::iter::sources::repeat_n::RepeatN::count] | Field[core::iter::sources::repeat_n::RepeatN::count] |
703+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1162:5:1187:5 | fn new | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
704+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1189:5:1214:5 | fn into_inner | Argument[0].Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
705+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1218:5:1351:5 | fn new_unchecked | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
706+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1449:5:1476:5 | fn set | Argument[self].Field[core::pin::Pin::__pointer].Reference | Field[core::pin::Pin::__pointer] |
707+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1480:5:1504:5 | fn into_inner_unchecked | Argument[0].Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
708+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1508:5:1535:5 | fn map_unchecked | Argument[self].Field[core::pin::Pin::__pointer].Reference | Field[core::pin::Pin::__pointer] |
709+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1508:5:1535:5 | fn map_unchecked | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
710+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1611:5:1640:5 | fn map_unchecked_mut | Argument[self].Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
711+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1611:5:1640:5 | fn map_unchecked_mut | Argument[self].Field[core::pin::Pin::__pointer].Field[0] | Field[core::pin::Pin::__pointer] |
712+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1611:5:1640:5 | fn map_unchecked_mut | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
713+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1611:5:1640:5 | fn map_unchecked_mut | ReturnValue.Field[core::pin::Pin::__pointer].Reference | Field[core::pin::Pin::__pointer] |
714+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1644:5:1654:5 | fn static_ref | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
715+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1658:5:1668:5 | fn static_mut | ReturnValue.Field[core::pin::Pin::__pointer] | Field[core::pin::Pin::__pointer] |
716+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/pin.rs:1674:5:1676:5 | fn deref | Argument[self].Field[core::pin::Pin::__pointer].Reference | Field[core::pin::Pin::__pointer] |
717+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/alignment.rs:203:5:206:5 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
718+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/stdarch-gen-arm/src/typekinds.rs:385:5:393:5 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
719+
| file:///Users/hvitved/.rustup/toolchains/1.90-aarch64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/stdarch-gen-arm/src/typekinds.rs:590:5:596:5 | fn from | Argument[0].Field[actix_web::http::header::content_length::ContentLength(0)] | Field[actix_web::http::header::content_length::ContentLength(0)] |
682720
#select
683721
| main.rs:16:10:16:20 | identity(...) | main.rs:15:13:15:21 | source(...) | main.rs:16:10:16:20 | identity(...) | $@ | main.rs:15:13:15:21 | source(...) | source(...) |
684722
| main.rs:16:10:16:20 | identity(...) | main.rs:15:13:15:21 | source(...) | main.rs:16:10:16:20 | identity(...) | $@ | main.rs:15:13:15:21 | source(...) | source(...) |

rust/ql/test/library-tests/dataflow/models/models.ql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import codeql.rust.dataflow.FlowSink
1313
import PathGraph
1414

1515
query predicate invalidSpecComponent(SummarizedCallable sc, string s, string c) {
16-
(sc.propagatesFlow(s, _, _) or sc.propagatesFlow(_, s, _)) and
16+
(sc.propagatesFlow(s, _, _, _, _, _) or sc.propagatesFlow(_, s, _, _, _, _)) and
1717
Private::External::invalidSpecComponent(s, c)
1818
}
1919

@@ -22,13 +22,10 @@ query predicate invalidSpecComponent(SummarizedCallable sc, string s, string c)
2222
private class SummarizedCallableIdentity extends SummarizedCallable::Range {
2323
SummarizedCallableIdentity() { this.getName().getText() = "identity" }
2424

25-
override predicate propagatesFlow(
26-
string input, string output, boolean preservesValue, string provenance
27-
) {
25+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
2826
input = "Argument[0]" and
2927
output = "ReturnValue" and
30-
preservesValue = true and
31-
provenance = "QL"
28+
preservesValue = true
3229
}
3330
}
3431

0 commit comments

Comments
 (0)