about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev+love@gmail.com>2022-12-06 12:48:50 +0900
committerGitHub <noreply@github.com>2022-12-06 12:48:50 +0900
commitaa0831092bd78333580f4d3608046a4e4fc2aa39 (patch)
tree26163e5985f507121469028a3c784cc925e49248
parent532fe7b8e043115477e33ad0d97dfe9469a2c236 (diff)
parent51ac2af99ffd46cf83760ceef2404dad0ce238a9 (diff)
downloadrust-aa0831092bd78333580f4d3608046a4e4fc2aa39.tar.gz
rust-aa0831092bd78333580f4d3608046a4e4fc2aa39.zip
Rollup merge of #105207 - RalfJung:interpret-clobber-return, r=oli-obk
interpret: clobber return place when calling function

Makes sure the callee cannot observe the previous contents of the return place, and the caller cannot read any of the old return place contents even if the function unwinds.

I don't think we can test for this though, that would require some strange hand-written MIR.

r? `````@oli-obk`````
-rw-r--r--compiler/rustc_const_eval/src/interpret/eval_context.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs
index 79450fccfc4..e17d3e516a6 100644
--- a/compiler/rustc_const_eval/src/interpret/eval_context.rs
+++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs
@@ -676,6 +676,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         return_to_block: StackPopCleanup,
     ) -> InterpResult<'tcx> {
         trace!("body: {:#?}", body);
+        // Clobber previous return place contents, nobody is supposed to be able to see them any more
+        // This also checks dereferenceable, but not align. We rely on all constructed places being
+        // sufficiently aligned (in particular we rely on `deref_operand` checking alignment).
+        self.write_uninit(return_place)?;
         // first push a stack frame so we have access to the local substs
         let pre_frame = Frame {
             body,