Skip to content

Commit

Permalink
Fix double mut on AssertZeroizeOnDrop (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Jan 27, 2022
1 parent 73ad6a6 commit 44bed6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions zeroize/src/lib.rs
Expand Up @@ -268,11 +268,11 @@ pub mod __internal {

/// Auto-deref workaround for deriving `ZeroizeOnDrop`.
pub trait AssertZeroizeOnDrop {
fn zeroize_or_on_drop(&mut self);
fn zeroize_or_on_drop(self);
}

impl<T: ZeroizeOnDrop> AssertZeroizeOnDrop for &mut T {
fn zeroize_or_on_drop(&mut self) {}
fn zeroize_or_on_drop(self) {}
}

/// Auto-deref workaround for deriving `ZeroizeOnDrop`.
Expand Down
15 changes: 15 additions & 0 deletions zeroize/tests/zeroize_derive.rs
Expand Up @@ -240,4 +240,19 @@ mod custom_derive_tests {

assert_eq!(value.0, 0);
}

#[test]
fn derive_only_zeroize_on_drop() {
#[derive(ZeroizeOnDrop)]
struct X([u8; 3]);

#[derive(ZeroizeOnDrop)]
struct Z(X);

let mut value = Z(X([1, 2, 3]));
unsafe {
std::ptr::drop_in_place(&mut value);
}
assert_eq!(&value.0 .0, &[0, 0, 0])
}
}

0 comments on commit 44bed6e

Please sign in to comment.