From b547e96b443a1049718700e5c2c440eb6515dc45 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Fri, 13 Oct 2017 15:19:55 +1100 Subject: [PATCH] Write poison to canary when removing item from diagnostic hashmap --- components/hashglobe/src/diagnostic.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/hashglobe/src/diagnostic.rs b/components/hashglobe/src/diagnostic.rs index 0c4df266b34..668a36f7ad2 100644 --- a/components/hashglobe/src/diagnostic.rs +++ b/components/hashglobe/src/diagnostic.rs @@ -1,6 +1,7 @@ use hash_map::HashMap; use std::borrow::Borrow; use std::hash::{BuildHasher, Hash}; +use std::ptr; use FailedAllocationError; @@ -9,6 +10,11 @@ const CANARY: usize = 0x42cafe99; #[cfg(target_pointer_width = "64")] const CANARY: usize = 0x42cafe9942cafe99; +#[cfg(target_pointer_width = "32")] +const POISON: usize = 0xdeadbeef; +#[cfg(target_pointer_width = "64")] +const POISON: usize = 0xdeadbeefdeadbeef; + #[derive(Clone, Debug)] enum JournalEntry { Insert(usize), @@ -130,6 +136,9 @@ impl DiagnosticHashMap { assert!(!self.readonly); self.journal.push(JournalEntry::Remove(self.map.make_hash(k).inspect())); + if let Some(v) = self.map.get_mut(k) { + unsafe { ptr::write_volatile(&mut v.0, POISON); } + } self.map.remove(k).map(|x| x.1) }