Skip to content

Commit 7bae451

Browse files
committed
Rust: Exclude results in macro invocations.
1 parent 26f8558 commit 7bae451

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ where
3939
// flow from a pointer or reference to the dereference
4040
AccessAfterLifetimeFlow::flowPath(sourceNode, sinkNode) and
4141
// check that the dereference is outside the lifetime of the target
42-
AccessAfterLifetime::dereferenceAfterLifetime(sourceNode.getNode(), sinkNode.getNode(), target)
42+
AccessAfterLifetime::dereferenceAfterLifetime(sourceNode.getNode(), sinkNode.getNode(), target) and
43+
// exclude sinks in macros, since these results are difficult to interpret
44+
not sinkNode.getNode().asExpr().getExpr().isFromMacroExpansion()
4345
select sinkNode.getNode(), sourceNode, sinkNode,
4446
"Access of a pointer to $@ after it's 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:655:11:655:25 | &raw const str2 | lifetime.rs:667:14:667:17 | ref1 | Access of a pointer to $@ after it's lifetime has ended. | lifetime.rs:651:7:651:10 | str2 | str2 |
2323
| lifetime.rs:692:13:692:14 | r1 | lifetime.rs:682:4:682:12 | &... | lifetime.rs:692:13:692:14 | r1 | Access of a pointer to $@ after it's lifetime has ended. | lifetime.rs:681:8:681:9 | v1 | v1 |
2424
| lifetime.rs:693:13:693:14 | r2 | lifetime.rs:686:5:686:13 | &... | lifetime.rs:693:13:693:14 | r2 | Access of a pointer to $@ after it's lifetime has ended. | lifetime.rs:685:8:685:9 | v2 | v2 |
25-
| lifetime.rs:725:2:725:12 | ptr | lifetime.rs:724:2:724:12 | &val | lifetime.rs:725:2:725:12 | ptr | Access of a pointer to $@ after it's lifetime has ended. | lifetime.rs:724:2:724:12 | val | val |
2625
| lifetime.rs:743:10:743:12 | ptr | lifetime.rs:733:9:733:12 | &val | lifetime.rs:743:10:743:12 | ptr | Access of a pointer to $@ after it's lifetime has ended. | lifetime.rs:731:6:731: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
@@ -721,8 +721,8 @@ macro_rules! my_macro {
721721
}
722722

723723
pub fn test_macros() {
724-
my_macro!(); // $ SPURIOUS: Source[rust/access-after-lifetime-ended]
725-
my_macro!(); // $ SPURIOUS: Alert[rust/access-after-lifetime-ended]
724+
my_macro!();
725+
my_macro!();
726726
}
727727

728728
// --- examples from qhelp ---

0 commit comments

Comments
 (0)