Rust: Add core::fmt::Write models - #22390
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Rust taint-flow models for formatted writes into output buffers.
Changes:
- Models
core::fmt::Writemethods andcore::fmt::write. - Expands legacy format-macro flow tests.
- Adds a change note.
Show a summary per file
| File | Description |
|---|---|
rust/ql/lib/codeql/rust/frameworks/stdlib/core.model.yml |
Adds formatting flow summaries. |
rust/ql/test/library-tests/format-macros-legacy/main.rs |
Adds formatted-write flow cases. |
rust/ql/test/library-tests/format-macros-legacy/inline-taint-flow.expected |
Updates flow expectations. |
rust/ql/test/library-tests/format-macros-legacy/FormatArgs.expected |
Updates format-argument expectations. |
rust/ql/test/library-tests/format-macros-legacy/LogInjection.expected |
Updates shifted result locations. |
rust/ql/lib/change-notes/2026-08-19-rust-core-fmt-flow-models.md |
Documents the analysis improvement. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Balanced
| # Fmt | ||
| - ["<_ as core::fmt::Write>::write_fmt", "Argument[0]", "Argument[self].Reference", "taint", "manual"] | ||
| - ["<_ as core::fmt::Write>::write_str", "Argument[0].Reference", "Argument[self].Reference", "taint", "manual"] | ||
| - ["<_ as core::fmt::Write>::write_char", "Argument[0]", "Argument[self].Reference", "taint", "manual"] |
There was a problem hiding this comment.
We don't need to test every single model individually.
| # Fmt | ||
| - ["<_ as core::fmt::Write>::write_fmt", "Argument[0]", "Argument[self].Reference", "taint", "manual"] | ||
| - ["<_ as core::fmt::Write>::write_str", "Argument[0].Reference", "Argument[self].Reference", "taint", "manual"] | ||
| - ["<_ as core::fmt::Write>::write_char", "Argument[0]", "Argument[self].Reference", "taint", "manual"] |
There was a problem hiding this comment.
This will have a semantic merge conflict with #22376.
| - ["<core::str>::trim", "Argument[self].Reference", "ReturnValue.Reference", "taint", "manual"] | ||
| - ["<core::str>::to_string", "Argument[self].Reference", "ReturnValue", "taint", "manual"] | ||
| # Fmt | ||
| - ["<_ as core::fmt::Write>::write_fmt", "Argument[0]", "Argument[self].Reference", "taint", "manual"] |
There was a problem hiding this comment.
Do we have a way of getting taint into an Arguments struct?
There was a problem hiding this comment.
We have test cases along the lines of format_args!("{}", source()). Do you mean that or something else?
There was a problem hiding this comment.
Yeah, I see that it somehow works, I'm just curious which model enables taint to get into an Arguments struct.
Add models for
core::fmt::Write, which is having a larger effect on taint analysis following recent changes. For #22346.@redsun82