Skip to content

zeroize: Vec<Z>::zeroize() zeroizes the initialized elements twice #1524

Description

@chpio

Hi!

utils/zeroize/src/lib.rs

Lines 528 to 536 in 03a330e

fn zeroize(&mut self) {
// Zeroize all the initialized elements.
self.iter_mut().zeroize();
// Set the Vec's length to 0 and drop all the elements.
self.clear();
// Zero the full capacity of `Vec`.
self.spare_capacity_mut().zeroize();
:

fn zeroize(&mut self) {
    // Zeroize all the initialized elements.
    self.iter_mut().zeroize();

    // Set the Vec's length to 0 and drop all the elements.
    self.clear();

    // Zero the full capacity of `Vec`.
    self.spare_capacity_mut().zeroize();
}

After self.clear(), len is 0, so self.spare_capacity_mut() in the third step covers the entire allocation, including the range that was already zeroized by the first step.

Is there are reason for that? If so, a comment might help.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions