-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: turn off macro expansion in code to be expanded by attribute macros #19572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the Rust extractor and QL query for CWE-696 to stop expanding inner macros when under attribute macros, and adjusts templates and tests to match the new behavior.
- Enhance
edgesFwd
to follow attribute macro expansions (with fallback) and refine alert messages. - Track
macro_context_depth
in the extractor and wrap AST emissions withpre_emit
/post_emit
to suppress nested expansions. - Update codegen templates and revise integration and query-test expectations to align spans and annotations.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
rust/ql/src/queries/security/CWE-696/BadCtorInitialization.ql | Handle attribute-macro expansions in edgesFwd and update the alert text |
rust/extractor/src/translate/base.rs | Introduce macro_context_depth , setup_item_expansion , and skip nested macro-call emissions |
rust/ast-generator/templates/extractor.mustache | Replace emit_detached with pre_emit /post_emit hooks around node emissions |
rust/ql/test/query-tests/security/CWE-696/test.rs | Adjust test annotations (Source /Alert ) for ctor initialization cases |
rust/ql/test/query-tests/security/CWE-696/BadCTorInitialization.expected | Update expected error spans and messages for ctor initialization tests |
rust/ql/integration-tests/macro-expansion/src/lib.rs | Add function body and nested #[repeat] call to test nested macro expansion |
rust/ql/integration-tests/macro-expansion/test.expected | Revise integration-test spans for expanded macros |
rust/ql/integration-tests/macro-expansion/summary.qlref | Add summary query for reduced macro-expansion statistics |
rust/ql/integration-tests/macro-expansion/summary.expected | Introduce expected macro-expansion summary stats |
Comments suppressed due to low confidence (2)
rust/ql/test/query-tests/security/CWE-696/test.rs:168
- The annotation on the
#[ctor]
forbad4_1
was changed to an Alert marker, and the corresponding Alert on the macro call was removed. To keep the test harness consistent, the attribute line should be// $ Source=source4_1
and the call line should have// $ Alert[rust/ctor-initialization]=source4_1
.
#[ctor] // $ Alert[rust/ctor-initialization]
rust/ql/integration-tests/macro-expansion/test.expected:4
- [nitpick] This mapping for
fn inner
→fn inner_0
at0
is repeated multiple times. Consolidate duplicate entries to one line per mapping for clarity.
| src/lib.rs:7:5:8:16 | fn inner | 0 | src/lib.rs:8:5:8:16 | fn inner_0 |
This commits were separated from #19314
The QL part was already reviewed in the context of that PR.