File tree Expand file tree Collapse file tree 2 files changed +62
-1
lines changed
rust/ql/test/query-tests/security/CWE-825 Expand file tree Collapse file tree 2 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -491,7 +491,7 @@ pub fn test_rc() {
491491 println ! ( " v3 = {v3}" ) ;
492492 println ! ( " v4 = {v4}" ) ;
493493 }
494- } // rc1 go out of scope, the reference count is 0, so p1, p2 are dangling
494+ } // rc1 goes out of scope, the reference count is 0, so p1, p2 are dangling
495495
496496 unsafe {
497497 let v5 = * p1; // $ MISSING: Alert
@@ -668,3 +668,58 @@ pub fn test_implicit_derefs() {
668668 println ! ( " v2 = {v2} (!)" ) ; // corrupt in practice
669669 }
670670}
671+
672+ // --- members ---
673+
674+ struct MyType {
675+ value : i64 ,
676+ }
677+
678+ impl MyType {
679+ fn test ( & self ) {
680+ let r1 = unsafe {
681+ let v1 = & self ;
682+ & v1. value
683+ } ;
684+ let ( r2, r3) = unsafe {
685+ let v2 = & self ;
686+ ( & v2. value ,
687+ & self . value )
688+ } ;
689+
690+ use_the_stack ( ) ;
691+
692+ let v1 = * r1;
693+ let v2 = * r2;
694+ let v3 = * r3;
695+ println ! ( " v1 = {v1}" ) ;
696+ println ! ( " v2 = {v2}" ) ;
697+ println ! ( " v3 = {v3}" ) ;
698+ }
699+ }
700+
701+ pub fn test_members ( ) {
702+ let mt = MyType { value : 1 } ;
703+ mt. test ( ) ;
704+ }
705+
706+ // --- macros ---
707+
708+ macro_rules! my_macro {
709+ ( ) => {
710+ let ptr: * const i64 ;
711+ {
712+ let val: i64 = 1 ;
713+ ptr = & val;
714+ }
715+
716+ unsafe {
717+ let v = * ptr;
718+ println!( " v = {v}" ) ;
719+ }
720+ } ;
721+ }
722+
723+ pub fn test_macros ( ) {
724+ my_macro ! ( ) ;
725+ }
Original file line number Diff line number Diff line change @@ -180,4 +180,10 @@ fn main() {
180180
181181 println ! ( "test_implicit_derefs:" ) ;
182182 test_implicit_derefs ( ) ;
183+
184+ println ! ( "test_members:" ) ;
185+ test_members ( ) ;
186+
187+ println ! ( "test_macros:" ) ;
188+ test_macros ( ) ;
183189}
You can’t perform that action at this time.
0 commit comments