Hacker News new | ask | show | jobs
by pornel 3916 days ago
The fact that a systems programming language must have a way to do this, and Rust sort-of has: (it'd be better if it was a stable API though)

https://doc.rust-lang.org/core/intrinsics/fn.volatile_set_me...

I know it's very tricky in presence of an optimizer. The current implementation in KeePassC uses the pointer after memset in Drop, so it might be just lucky (https://github.com/raymontag/rust-keepass/issues/4).

3 comments

I think you could just use black_box to get around the optimizer:

http://doc.rust-lang.org/1.1.0/test/fn.black_box.html

I've never actually tried it outside of tests, so I don't know if it applies here.

There is no such way in _C_.

C only promises the behavior of the C abstract machine. Data will randomly get spilled from registers into random places on the stack where you may be completely unable to reach them to zeroize them.

All you can do is best effort, in C-- I wouldn't expect rust to be better here.