Skip to content

Commit dbd5dab

Browse files
author
Paolo Tranquilli
committed
Rust: adapt BadCtorInitialization.ql to attribute macro expansion
1 parent 7cc3219 commit dbd5dab

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

rust/ql/src/queries/security/CWE-696/BadCtorInitialization.ql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ class PathElement = AstNode;
4444
* reachable from a source.
4545
*/
4646
predicate edgesFwd(PathElement pred, PathElement succ) {
47-
// attribute (source) -> callable
48-
pred.(CtorAttr) = succ.(Callable).getAnAttr()
47+
// attribute (source) -> function in macro expansion
48+
exists(Function f |
49+
pred.(CtorAttr) = f.getAnAttr() and
50+
(
51+
f.getAttributeMacroExpansion().getAnItem() = succ.(Callable)
52+
or
53+
// if for some reason the ctor/dtor macro expansion failed, fall back to looking into the unexpanded item
54+
not f.hasAttributeMacroExpansion() and f = succ.(Callable)
55+
)
56+
)
4957
or
58+
// callable -> callable attribute macro expansion
5059
// [forwards reachable] callable -> enclosed call
5160
edgesFwd(_, pred) and
5261
pred = succ.(CallExprBase).getEnclosingCallable()

0 commit comments

Comments
 (0)