From 06bad8ba42ad9b69bcfdb1f95f25a45b1c1a86b2 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 21 Dec 2015 15:47:36 -0600 Subject: [PATCH] revocation: fix integer underflow infinite loop bug in sha chain * `i := toDerive - 1` created an unsigned integer, the last loop iteration subtracted from zero causing this to underflow creating an infinite loop * Instead, initialized `i` as an int, and cast to uint as needed --- revocation/shachain.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/revocation/shachain.go b/revocation/shachain.go index e76897d3..52d724ad 100644 --- a/revocation/shachain.go +++ b/revocation/shachain.go @@ -72,11 +72,11 @@ func derive(from, to uint64, startingHash [32]byte) [32]byte { numBranches := from ^ to toDerive := uint64(math.Log2(float64(numBranches))) // uh..... - for i := toDerive - 1; i >= 0; i-- { - if (numBranches>>i)&1 == 1 { + for i := int(toDerive - 1); i >= 0; i-- { + if (numBranches>>uint(i))&1 == 1 { // Flip the ith bit, then hash the current state to // advance down the tree. - nextHash[i/8] ^= (1 << (i % 8)) + nextHash[i/8] ^= (1 << (uint(i) % 8)) nextHash = sha256.Sum256(nextHash[:]) } }