Skip to content

Conversation

@daxpedda
Copy link
Collaborator

I noticed that the following would fail to compile:

#[derive_where(ZeroizeOnDrop)]
enum Test<T> {
    A(PhantomData<T>),
    #[derive_where(skip_inner)]
    B(PhantomData<T>),
}

Because it produces the following:

impl<T> Drop for Test<T> {
    fn drop(&mut self) {
        match self {
            Test::A(ref mut __field_0) => {
                __field_0.zeroize_or_on_drop();
            }
        }
    }
}

Instead, we now make sure to also cover variants that are skipped, but their body is just empty now.

See the test I added for a more complete example.

@daxpedda daxpedda requested a review from ModProg April 14, 2025 20:40
@daxpedda daxpedda force-pushed the zeroize-on-drop-fix branch from 4b5ad2e to 65d6197 Compare April 14, 2025 20:52
@daxpedda
Copy link
Collaborator Author

I discovered another bug!

Apparently the following:

#[derive_where(ZeroizeOnDrop)]
enum Test<T> {
    A(PhantomData<T>),
    #[derive_where(skip_inner)]
    B(PhantomData<T>),
}

Would generate multiple calls to Zeroize::zeroize():

impl<T> Drop for Test<T> {
    fn drop(&mut self) {
        Zeroize::zeroize(self);
        Zeroize::zeroize(self);
    }
}

@daxpedda daxpedda force-pushed the zeroize-on-drop-fix branch from 65d6197 to b52e808 Compare April 15, 2025 10:26
@daxpedda daxpedda merged commit 957f5c9 into ModProg:main Apr 15, 2025
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants