From 9d4dcf615ab93aca8e0909440841bac5c9057e73 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 11 Jun 2015 18:23:26 -0700 Subject: [PATCH] Bug 1174046 - Fix PLDHashTable::Iterator in chaos mode again. r=froydnj, a=philor CLOSED TREE If you use PLDHashTable::Iterator in chaos mode with a table with zero capacity, a |% 0| operation takes place in randomUint32LessThan. This change avoids that. --- mfbt/ChaosMode.h | 1 + xpcom/glue/pldhash.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mfbt/ChaosMode.h b/mfbt/ChaosMode.h index 9378f665154..ca943a1e76f 100644 --- a/mfbt/ChaosMode.h +++ b/mfbt/ChaosMode.h @@ -81,6 +81,7 @@ public: */ static uint32_t randomUint32LessThan(uint32_t aBound) { + MOZ_ASSERT(aBound != 0); return uint32_t(rand()) % aBound; } }; diff --git a/xpcom/glue/pldhash.cpp b/xpcom/glue/pldhash.cpp index ac3f080d79f..c7f22d83736 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -910,7 +910,7 @@ PLDHashTable::Iterator::Iterator(const PLDHashTable* aTable) // mEntryAddr, respectively. uint32_t capacity = mTable->Capacity(); - if (ChaosMode::isActive(ChaosMode::HashTableIteration)) { + if (ChaosMode::isActive(ChaosMode::HashTableIteration) && capacity > 0) { // Start iterating at a random point in the hashtable. It would be // even more chaotic to iterate in fully random order, but that's a lot // more work.