Skip to content

Commit 78f855d

Browse files
committed
Rust: Make the manual model for Option::map more accurate.
1 parent 75ffb5f commit 78f855d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ extensions:
103103
- ["<_ as core::iter::traits::iterator::Iterator>::chain", "Argument[0]", "ReturnValue", "taint", "manual"]
104104
- ["<_ as core::iter::traits::iterator::Iterator>::take", "Argument[self]", "ReturnValue", "taint", "manual"]
105105
# Option
106-
- ["<core::option::Option>::map", "Argument[self]", "ReturnValue", "taint", "manual"]
106+
- ["<core::option::Option>::map", "Argument[self]", "Argument[0].Parameter[0]", "taint", "manual"]
107+
- ["<core::option::Option>::map", "Argument[0].ReturnValue", "ReturnValue", "taint", "manual"]
107108
# Pin
108109
- ["<core::pin::Pin>::new", "Argument[0]", "ReturnValue.Field[core::pin::Pin::pointer]", "value", "manual"]
109110
# This model is not precise, but helps in cases where a `Pin` is implicitly dereferenced.

rust/ql/test/query-tests/security/CWE-117/LogInjection.expected

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ edges
9898
| main.rs:142:32:142:59 | ...: Option::<...> | main.rs:143:22:143:27 | o_path | provenance | |
9999
| main.rs:143:13:143:18 | m_path | main.rs:145:26:145:31 | m_path | provenance | |
100100
| main.rs:143:22:143:27 | o_path | main.rs:143:22:143:38 | o_path.map(...) | provenance | MaD:14 |
101+
| main.rs:143:22:143:27 | o_path | main.rs:143:34:143:34 | ... | provenance | MaD:14 |
101102
| main.rs:143:22:143:38 | o_path.map(...) | main.rs:143:13:143:18 | m_path | provenance | |
103+
| main.rs:143:34:143:34 | ... | main.rs:143:37:143:37 | x | provenance | |
102104
| main.rs:145:18:145:40 | MacroExpr | main.rs:145:9:145:16 | ...::_print | provenance | MaD:3 Sink:MaD:3 |
103105
| main.rs:145:26:145:31 | m_path | main.rs:145:26:145:40 | m_path.unwrap() | provenance | MaD:15 |
104106
| main.rs:145:26:145:40 | m_path.unwrap() | main.rs:145:18:145:40 | MacroExpr | provenance | |
@@ -117,7 +119,7 @@ models
117119
| 11 | Summary: <_ as core::iter::traits::iterator::Iterator>::nth; Argument[self].Reference.Element; ReturnValue.Field[core::option::Option::Some(0)]; value |
118120
| 12 | Summary: <alloc::string::String as core::ops::arith::Add>::add; Argument[0].Reference; ReturnValue; taint |
119121
| 13 | Summary: <alloc::vec::Vec as core::ops::deref::Deref>::deref; Argument[self].Reference.Element; ReturnValue.Reference.Element; value |
120-
| 14 | Summary: <core::option::Option>::map; Argument[self]; ReturnValue; taint |
122+
| 14 | Summary: <core::option::Option>::map; Argument[self]; Argument[0].Parameter[0]; taint |
121123
| 15 | Summary: <core::option::Option>::unwrap; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
122124
| 16 | Summary: <core::option::Option>::unwrap_or; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
123125
| 17 | Summary: <core::option::Option>::unwrap_or_default; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
@@ -212,9 +214,12 @@ nodes
212214
| main.rs:143:13:143:18 | m_path | semmle.label | m_path |
213215
| main.rs:143:22:143:27 | o_path | semmle.label | o_path |
214216
| main.rs:143:22:143:38 | o_path.map(...) | semmle.label | o_path.map(...) |
217+
| main.rs:143:34:143:34 | ... | semmle.label | ... |
218+
| main.rs:143:37:143:37 | x | semmle.label | x |
215219
| main.rs:145:9:145:16 | ...::_print | semmle.label | ...::_print |
216220
| main.rs:145:18:145:40 | MacroExpr | semmle.label | MacroExpr |
217221
| main.rs:145:26:145:31 | m_path | semmle.label | m_path |
218222
| main.rs:145:26:145:40 | m_path.unwrap() | semmle.label | m_path.unwrap() |
219223
| main.rs:152:28:152:30 | get | semmle.label | get |
220224
subpaths
225+
| main.rs:143:22:143:27 | o_path | main.rs:143:34:143:34 | ... | main.rs:143:37:143:37 | x | main.rs:143:22:143:38 | o_path.map(...) |

0 commit comments

Comments
 (0)