diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2022-06-28 18:16:25 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2022-07-05 10:35:39 +0200 |
commit | 39f1c9cc081e03ae521f4cb78007d9c63da83839 (patch) | |
tree | dafa97fdf250afded405bf83c34cf462a3a41567 | |
parent | 8f39baaa16c4a5d775cadcd76cdc32639eeef1dd (diff) |
ipc: Securely delete Sexp strings.
-rw-r--r-- | ipc/src/sexp.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/ipc/src/sexp.rs b/ipc/src/sexp.rs index 8ff75eca..7a8ce18c 100644 --- a/ipc/src/sexp.rs +++ b/ipc/src/sexp.rs @@ -396,17 +396,22 @@ impl String_ { /// Creates a Protected memory region from this String. /// /// Securely erases the contents of the original String. - pub fn into_protected(mut self) -> Protected { + pub fn into_protected(self) -> Protected { let r = Protected::from(&self.0[..]); + drop(self); // Securely erases this string. + r + } +} + +impl Drop for String_ { + fn drop(&mut self) { unsafe { memsec::memzero(self.0.as_mut_ptr(), self.0.len()); if let Some(p) = self.1.as_mut() { memsec::memzero(p.as_mut_ptr(), p.len()); } } - r } - } impl From<&str> for String_ { |