Skip to content

Commit 1cfc8f6

Browse files
authored
Merge pull request github#18769 from hvitved/rust/mad-field-token
Rust: Use `Field` MaD token instead of `Variant`, `Struct`, `Tuple`
2 parents 50584c8 + e9c2503 commit 1cfc8f6

File tree

20 files changed

+420
-418
lines changed

20 files changed

+420
-418
lines changed

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

+27-30
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,36 @@ module Input implements InputSig<Location, RustDataFlow> {
6161

6262
string encodeContent(ContentSet cs, string arg) {
6363
exists(Content c | cs = TSingletonContentSet(c) |
64-
exists(Addressable a, int pos |
65-
// TODO: calculate in QL
66-
arg = a.getExtendedCanonicalPath() + "(" + pos + ")"
67-
|
68-
result = "Struct" and
69-
c.(TupleFieldContent).isStructField(a, pos)
64+
result = "Field" and
65+
(
66+
exists(Addressable a, int pos |
67+
// TODO: calculate in QL
68+
arg = a.getExtendedCanonicalPath() + "(" + pos + ")"
69+
|
70+
c.(TupleFieldContent).isStructField(a, pos)
71+
or
72+
c.(TupleFieldContent).isVariantField(a, pos)
73+
)
7074
or
71-
result = "Variant" and
72-
c.(TupleFieldContent).isVariantField(a, pos)
73-
)
74-
or
75-
exists(Addressable a, string field |
76-
// TODO: calculate in QL
77-
arg = a.getExtendedCanonicalPath() + "::" + field
78-
|
79-
result = "Struct" and
80-
c.(RecordFieldContent).isStructField(a, field)
75+
exists(Addressable a, string field |
76+
// TODO: calculate in QL
77+
arg = a.getExtendedCanonicalPath() + "::" + field
78+
|
79+
c.(RecordFieldContent).isStructField(a, field)
80+
or
81+
c.(RecordFieldContent).isVariantField(a, field)
82+
)
8183
or
82-
result = "Variant" and
83-
c.(RecordFieldContent).isVariantField(a, field)
84-
)
85-
or
86-
result = "Variant" and
87-
c =
88-
any(VariantInLibTupleFieldContent v |
89-
arg = v.getExtendedCanonicalPath() + "(" + v.getPosition() + ")"
84+
c =
85+
any(VariantInLibTupleFieldContent v |
86+
arg = v.getExtendedCanonicalPath() + "(" + v.getPosition() + ")"
87+
)
88+
or
89+
exists(int pos |
90+
c = TTuplePositionContent(pos) and
91+
arg = pos.toString()
9092
)
93+
)
9194
or
9295
result = "Reference" and
9396
c = TReferenceContent() and
@@ -97,12 +100,6 @@ module Input implements InputSig<Location, RustDataFlow> {
97100
c = TElementContent() and
98101
arg = ""
99102
or
100-
exists(int pos |
101-
result = "Tuple" and
102-
c = TTuplePositionContent(pos) and
103-
arg = pos.toString()
104-
)
105-
or
106103
result = "Future" and
107104
c = TFutureContent() and
108105
arg = ""

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@
2929
* and/or a comma-separated list.
3030
* - `ReturnValue`: the value returned by a function call.
3131
* - `Element`: an element in a collection.
32-
* - `Variant[v::f]`: field `f` of the variant with canonical path `v`, for example
33-
* `Variant[crate::ihex::Record::Data::value]`.
34-
* - `Variant[v(i)]`: position `i` inside the variant with canonical path `v`, for example
35-
* `Variant[crate::option::Option::Some(0)]`.
36-
* - `Struct[s::f]`: field `f` of the struct with canonical path `v`, for example
37-
* `Struct[crate::process::Child::stdin]`.
38-
* - `Tuple[i]`: the `i`th element of a tuple.
32+
* - `Field[t::f]`: field `f` of the variant/struct with canonical path `t`, for example
33+
* `Field[crate::ihex::Record::Data::value]`.
34+
* - `Field[t(i)]`: position `i` inside the variant/struct with canonical path `v`, for example
35+
* `Field[crate::option::Option::Some(0)]`.
36+
* - `Field[i]`: the `i`th element of a tuple.
3937
* 4. The `kind` column is a tag that can be referenced from QL to determine to
4038
* which classes the interpreted elements should be added. For example, for
4139
* sources `"remote"` indicates a default remote flow source, and for summaries

rust/ql/lib/codeql/rust/frameworks/http.model.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ extensions:
33
pack: codeql/rust-all
44
extensible: sourceModel
55
data:
6-
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http1::SendRequest>::send_request", "ReturnValue.Future.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
7-
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http2::SendRequest>::send_request", "ReturnValue.Future.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
8-
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http1::SendRequest>::try_send_request", "ReturnValue.Future.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
9-
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http2::SendRequest>::try_send_request", "ReturnValue.Future.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
6+
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http1::SendRequest>::send_request", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
7+
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http2::SendRequest>::send_request", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
8+
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http1::SendRequest>::try_send_request", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
9+
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::conn::http2::SendRequest>::try_send_request", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
1010
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::Client>::get", "ReturnValue.Future", "remote", "manual"]
1111
- ["repo:https://github.com/hyperium/hyper:hyper", "<crate::client::Client>::request", "ReturnValue.Future", "remote", "manual"]
1212
- ["repo:https://github.com/hyperium/hyper-util:hyper-util", "<crate::client::legacy::Client>::get", "ReturnValue.Future", "remote", "manual"]

rust/ql/lib/codeql/rust/frameworks/log.model.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ extensions:
1313
- ["lang:std", "<crate::io::stdio::StderrLock as crate::io::Write>::write", "Argument[0]", "log-injection", "manual"]
1414
- ["lang:std", "<crate::io::stdio::StderrLock as crate::io::Write>::write_all", "Argument[0]", "log-injection", "manual"]
1515
- ["lang:core", "crate::panicking::panic_fmt", "Argument[0]", "log-injection", "manual"]
16-
- ["lang:core", "crate::panicking::assert_failed", "Argument[3].Variant[crate::option::Option::Some(0)]", "log-injection", "manual"]
16+
- ["lang:core", "crate::panicking::assert_failed", "Argument[3].Field[crate::option::Option::Some(0)]", "log-injection", "manual"]
1717
- ["lang:core", "<crate::option::Option>::expect", "Argument[0]", "log-injection", "manual"]

rust/ql/lib/codeql/rust/frameworks/reqwest.model.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ extensions:
33
pack: codeql/rust-all
44
extensible: sourceModel
55
data:
6-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "crate::get", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
7-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "crate::blocking::get", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "remote", "manual"]
6+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "crate::get", "ReturnValue.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
7+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "crate::blocking::get", "ReturnValue.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
88
- addsTo:
99
pack: codeql/rust-all
1010
extensible: summaryModel
1111
data:
12-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::text", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "taint", "manual"]
13-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::text_with_charset", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "taint", "manual"]
14-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::bytes", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "taint", "manual"]
15-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::chunk", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)].Variant[crate::option::Option::Some(0)]", "taint", "manual"]
16-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::text", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "taint", "manual"]
17-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::text_with_charset", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "taint", "manual"]
18-
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::bytes", "Argument[self]", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "taint", "manual"]
12+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::text", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
13+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::text_with_charset", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
14+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::bytes", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
15+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::response::Response>::chunk", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)].Field[crate::option::Option::Some(0)]", "taint", "manual"]
16+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::text", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
17+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::text_with_charset", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
18+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::bytes", "Argument[self]", "ReturnValue.Field[crate::result::Result::Ok(0)]", "taint", "manual"]

rust/ql/lib/codeql/rust/frameworks/rusqlite.model.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extensions:
1414
pack: codeql/rust-all
1515
extensible: sourceModel
1616
data:
17-
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::row::Row>::get", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "database", "manual"]
17+
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::row::Row>::get", "ReturnValue.Field[crate::result::Result::Ok(0)]", "database", "manual"]
1818
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::row::Row>::get_unwrap", "ReturnValue", "database", "manual"]
19-
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::row::Row>::get_ref", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "database", "manual"]
19+
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::row::Row>::get_ref", "ReturnValue.Field[crate::result::Result::Ok(0)]", "database", "manual"]
2020
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::row::Row>::get_ref_unwrap", "ReturnValue", "database", "manual"]

rust/ql/lib/codeql/rust/frameworks/stdlib/env.model.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ extensions:
55
data:
66
- ["lang:std", "crate::env::args", "ReturnValue.Element", "command-line-source", "manual"]
77
- ["lang:std", "crate::env::args_os", "ReturnValue.Element", "command-line-source", "manual"]
8-
- ["lang:std", "crate::env::current_dir", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "command-line-source", "manual"]
9-
- ["lang:std", "crate::env::current_exe", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "command-line-source", "manual"]
10-
- ["lang:std", "crate::env::home_dir", "ReturnValue.Variant[crate::option::Option::Some(0)]", "command-line-source", "manual"]
11-
- ["lang:std", "crate::env::var", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "environment-source", "manual"]
12-
- ["lang:std", "crate::env::var_os", "ReturnValue.Variant[crate::option::Option::Some(0)]", "environment-source", "manual"]
8+
- ["lang:std", "crate::env::current_dir", "ReturnValue.Field[crate::result::Result::Ok(0)]", "command-line-source", "manual"]
9+
- ["lang:std", "crate::env::current_exe", "ReturnValue.Field[crate::result::Result::Ok(0)]", "command-line-source", "manual"]
10+
- ["lang:std", "crate::env::home_dir", "ReturnValue.Field[crate::option::Option::Some(0)]", "command-line-source", "manual"]
11+
- ["lang:std", "crate::env::var", "ReturnValue.Field[crate::result::Result::Ok(0)]", "environment-source", "manual"]
12+
- ["lang:std", "crate::env::var_os", "ReturnValue.Field[crate::option::Option::Some(0)]", "environment-source", "manual"]
1313
- ["lang:std", "crate::env::vars", "ReturnValue.Element", "environment-source", "manual"]
1414
- ["lang:std", "crate::env::vars_os", "ReturnValue.Element", "environment-source", "manual"]

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ extensions:
88
# Hint
99
- ["lang:core", "crate::hint::must_use", "Argument[0]", "ReturnValue", "value", "manual"]
1010
# Iterator
11-
- ["lang:core", "crate::iter::traits::iterator::Iterator::nth", "Argument[self].Element", "ReturnValue.Variant[crate::option::Option::Some(0)]", "value", "manual"]
11+
- ["lang:core", "crate::iter::traits::iterator::Iterator::nth", "Argument[self].Element", "ReturnValue.Field[crate::option::Option::Some(0)]", "value", "manual"]
1212
- ["lang:core", "crate::iter::traits::iterator::Iterator::collect", "Argument[self].Element", "ReturnValue.Element", "value", "manual"]
1313
# Option
14-
- ["lang:core", "<crate::option::Option>::expect", "Argument[self].Variant[crate::option::Option::Some(0)]", "ReturnValue", "value", "manual"]
14+
- ["lang:core", "<crate::option::Option>::expect", "Argument[self].Field[crate::option::Option::Some(0)]", "ReturnValue", "value", "manual"]
1515
# Result
16-
- ["lang:core", "<crate::result::Result>::unwrap", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
17-
- ["lang:core", "<crate::result::Result>::unwrap_or", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
16+
- ["lang:core", "<crate::result::Result>::unwrap", "Argument[self].Field[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
17+
- ["lang:core", "<crate::result::Result>::unwrap_or", "Argument[self].Field[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
1818
- ["lang:core", "<crate::result::Result>::unwrap_or", "Argument[0]", "ReturnValue", "value", "manual"]
19-
- ["lang:core", "<crate::result::Result>::unwrap_or_default", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
20-
- ["lang:core", "<crate::result::Result>::unwrap_or_else", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
19+
- ["lang:core", "<crate::result::Result>::unwrap_or_default", "Argument[self].Field[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
20+
- ["lang:core", "<crate::result::Result>::unwrap_or_else", "Argument[self].Field[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
2121
- ["lang:core", "<crate::result::Result>::unwrap_or_else", "Argument[0].ReturnValue", "ReturnValue", "value", "manual"]
22-
- ["lang:core", "<crate::result::Result>::unwrap_unchecked", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
23-
- ["lang:core", "<crate::result::Result>::unwrap_err", "Argument[self].Variant[crate::result::Result::Err(0)]", "ReturnValue", "value", "manual"]
24-
- ["lang:core", "<crate::result::Result>::unwrap_err_unchecked", "Argument[self].Variant[crate::result::Result::Err(0)]", "ReturnValue", "value", "manual"]
25-
- ["lang:core", "<crate::result::Result>::expect", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
26-
- ["lang:core", "<crate::result::Result>::expect_err", "Argument[self].Variant[crate::result::Result::Err(0)]", "ReturnValue", "value", "manual"]
22+
- ["lang:core", "<crate::result::Result>::unwrap_unchecked", "Argument[self].Field[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
23+
- ["lang:core", "<crate::result::Result>::unwrap_err", "Argument[self].Field[crate::result::Result::Err(0)]", "ReturnValue", "value", "manual"]
24+
- ["lang:core", "<crate::result::Result>::unwrap_err_unchecked", "Argument[self].Field[crate::result::Result::Err(0)]", "ReturnValue", "value", "manual"]
25+
- ["lang:core", "<crate::result::Result>::expect", "Argument[self].Field[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
26+
- ["lang:core", "<crate::result::Result>::expect_err", "Argument[self].Field[crate::result::Result::Err(0)]", "ReturnValue", "value", "manual"]
2727
# String
2828
- ["lang:alloc", "<crate::string::String>::as_str", "Argument[self]", "ReturnValue", "taint", "manual"]
2929
- ["lang:alloc", "<crate::string::String>::as_bytes", "Argument[self]", "ReturnValue", "taint", "manual"]

rust/ql/lib/codeql/rust/frameworks/tokio-postgres.model.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ extensions:
2121
extensible: sourceModel
2222
data:
2323
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::get", "ReturnValue", "database", "manual"]
24-
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::try_get", "ReturnValue.Variant[crate::result::Result::Ok(0)]", "database", "manual"]
24+
- ["repo:https://github.com/sfackler/rust-postgres:tokio-postgres", "<crate::row::Row>::try_get", "ReturnValue.Field[crate::result::Result::Ok(0)]", "database", "manual"]

0 commit comments

Comments
 (0)