Clear memory with volatile intrinsic
AFAIK the optimizer is free to optimize out memory writes if it finds that the memory isn't read afterwards.
This can potentially affect secure string deletion:
https://github.com/raymontag/rust-keepass/blob/2b7b701b6954160fa86d1e3dddf0154654ac510b/src/sec_str/mod.rs#L62,L63
There's an (unstable) intrinsic that guarantees the write won't be optimized out: https://doc.rust-lang.org/core/intrinsics/fn.volatile_set_memory.html
Thanks for the hint, I will look at it.
After researching a little bit it seems you're right, one has to use the volatile-functions for this. However it is unprobable that these become stable. But I'm verifying this ATM in the Rust-forum. libsodium would have a function for this, however linking to it only for this particular usecase sucks. It seems I have to write my own function for this via ffi...
We could also look at the assembler that gets generated. It's a bit tricky with rust, but its doable.
I've used volatile_set_memory in 3c20a8a6801ce56e2186dd122280f1c97c128e49, so it's fixed now. We will make a code review in the following days to see if there are more such caveats.