Skip to content

Commit 087e666

Browse files
committed
Rust: Exclude sources in macro expansions.
1 parent 1682460 commit 087e666

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

rust/ql/src/queries/security/CWE-825/AccessAfterLifetime.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ where
4040
AccessAfterLifetimeFlow::flowPath(sourceNode, sinkNode) and
4141
// check that the dereference is outside the lifetime of the target
4242
AccessAfterLifetime::dereferenceAfterLifetime(sourceNode.getNode(), sinkNode.getNode(), target) and
43-
// exclude sinks in macros, since these results are difficult to interpret
43+
// exclude cases with sources / sinks in macros, since these results are difficult to interpret
44+
not sourceNode.getNode().asExpr().getExpr().isFromMacroExpansion() and
4445
not sinkNode.getNode().asExpr().getExpr().isFromMacroExpansion()
4546
select sinkNode.getNode(), sourceNode, sinkNode,
4647
"Access of a pointer to $@ after its lifetime has ended.", target, target.toString()

rust/ql/test/query-tests/security/CWE-825/AccessAfterLifetime.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
| lifetime.rs:667:14:667:17 | ref1 | lifetime.rs:654:31:654:35 | &str1 | lifetime.rs:667:14:667:17 | ref1 | Access of a pointer to $@ after its lifetime has ended. | lifetime.rs:653:8:653:11 | str1 | str1 |
2323
| lifetime.rs:667:14:667:17 | ref1 | lifetime.rs:655:11:655:25 | &raw const str2 | lifetime.rs:667:14:667:17 | ref1 | Access of a pointer to $@ after its lifetime has ended. | lifetime.rs:651:7:651:10 | str2 | str2 |
2424
| lifetime.rs:734:12:734:13 | r1 | lifetime.rs:719:26:719:34 | &... | lifetime.rs:734:12:734:13 | r1 | Access of a pointer to $@ after its lifetime has ended. | lifetime.rs:719:19:719:20 | v2 | v2 |
25-
| lifetime.rs:771:12:771:14 | ptr | lifetime.rs:769:12:769:23 | &val | lifetime.rs:771:12:771:14 | ptr | Access of a pointer to $@ after its lifetime has ended. | lifetime.rs:769:12:769:23 | val | val |
2625
| lifetime.rs:791:10:791:12 | ptr | lifetime.rs:781:9:781:12 | &val | lifetime.rs:791:10:791:12 | ptr | Access of a pointer to $@ after its lifetime has ended. | lifetime.rs:779:6:779:8 | val | val |
2726
edges
2827
| deallocation.rs:148:6:148:7 | p1 | deallocation.rs:151:14:151:15 | p1 | provenance | |

rust/ql/test/query-tests/security/CWE-825/lifetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,9 @@ pub fn test_macros() {
766766
my_macro1!();
767767
my_macro1!();
768768

769-
let ptr = my_macro2!(); // $ SPURIOUS: Source[rust/access-after-lifetime-ended]=ptr
769+
let ptr = my_macro2!();
770770
unsafe {
771-
let v = *ptr; // $ SPURIOUS: Alert[rust/access-after-lifetime-ended]=ptr
771+
let v = *ptr;
772772
println!(" v = {v}");
773773
}
774774
}

0 commit comments

Comments
 (0)