From 71b93d55effae6a74bbbbafe7057e1f97d692a74 Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Wed, 25 Oct 2023 15:26:14 +0200 Subject: [PATCH] rust/pv: fix Invalid write of size 1 Fix a valgrind finding. Fix an invalid read/write of one byte after the actual struct to clear. Not fixing this may result in a illegal write or memory corruption of the program. Fortunately, for the actual only user, pvsecret this is not the case. Fixes: c6f621d0 ("rust: Add library for pv tools") Signed-off-by: Steffen Eiden --- rust/pv/src/secret.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/pv/src/secret.rs b/rust/pv/src/secret.rs index cdef9ef8..88287c8e 100644 --- a/rust/pv/src/secret.rs +++ b/rust/pv/src/secret.rs @@ -34,8 +34,8 @@ impl Zeroize for Vec { // * Vec allocated at least capacity elements continuously // * dst points always to a valid location unsafe { + std::ptr::write_volatile(dst, 0); dst = dst.add(1); - std::ptr::write_volatile(dst, 0) } } std::sync::atomic::compiler_fence(std::sync::atomic::Ordering::SeqCst);