Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
01ea3d4b
Commit
01ea3d4b
authored
May 24, 2016
by
Richard van der Hoff
Browse files
Fix handling of integer wraparound in megolm.c
parent
1f314271
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/megolm.c
View file @
01ea3d4b
...
...
@@ -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
;
...
...
tests/test_megolm.cpp
View file @
01ea3d4b
...
...
@@ -82,4 +82,20 @@ std::uint8_t random_bytes[] =
assert_equals
(
expected3
,
megolm_get_data
(
&
mr
),
MEGOLM_RATCHET_LENGTH
);
}
{
TestCase
test_case
(
"Megolm::advance wraparound"
);
Megolm
mr1
,
mr2
;
megolm_init
(
&
mr1
,
random_bytes
,
0xffffffffUL
);
megolm_advance_to
(
&
mr1
,
0x1000000
);
assert_equals
(
0x1000000U
,
mr1
.
counter
);
megolm_init
(
&
mr2
,
random_bytes
,
0
);
megolm_advance_to
(
&
mr2
,
0x2000000
);
assert_equals
(
0x2000000U
,
mr2
.
counter
);
assert_equals
(
megolm_get_data
(
&
mr2
),
megolm_get_data
(
&
mr1
),
MEGOLM_RATCHET_LENGTH
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment