aboutsummaryrefslogtreecommitdiff
path: root/src/megolm.c
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-05-24 17:52:35 +0100
committerRichard van der Hoff <richard@matrix.org>2016-05-24 17:52:35 +0100
commit01ea3d4b9a3c6f3e0303c2d421a248715a96af99 (patch)
tree553ba1b809d0cc44e96e3860cee28f9aac4f4802 /src/megolm.c
parent1f31427139acdef00f24aac13b67224fa915f9e7 (diff)
Fix handling of integer wraparound in megolm.c
Diffstat (limited to 'src/megolm.c')
-rw-r--r--src/megolm.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/megolm.c b/src/megolm.c
index 6d8af08..a969b36 100644
--- a/src/megolm.c
+++ b/src/megolm.c
@@ -108,8 +108,12 @@ void megolm_advance_to(Megolm *megolm, uint32_t advance_to) {
uint32_t mask = (~(uint32_t)0) << shift;
int k;
- /* how many times to we need to rehash this part? */
- int steps = (advance_to >> shift) - (megolm->counter >> shift);
+ /* how many times do we need to rehash this part?
+ *
+ * '& 0xff' ensures we handle integer wraparound correctly
+ */
+ unsigned int steps =
+ ((advance_to >> shift) - (megolm->counter >> shift)) & 0xff;
if (steps == 0) {
continue;