ikev2: Make sure to correctly compare nonces of unequal length
The previous code would not correctly compare nonces of unequal length where the shorter is the prefix of the longer one.
This commit is contained in:
@@ -2957,8 +2957,7 @@ METHOD(child_create_t, get_config, child_cfg_t*,
|
||||
METHOD(child_create_t, get_lower_nonce, chunk_t,
|
||||
private_child_create_t *this)
|
||||
{
|
||||
if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
|
||||
min(this->my_nonce.len, this->other_nonce.len)) < 0)
|
||||
if (chunk_compare_prefix(this->my_nonce, this->other_nonce) < 0)
|
||||
{
|
||||
return this->my_nonce;
|
||||
}
|
||||
|
||||
@@ -564,8 +564,7 @@ static bool lost_collision(private_child_rekey_t *this)
|
||||
this_nonce = this->child_create->get_lower_nonce(this->child_create);
|
||||
other_nonce = other->child_create->get_lower_nonce(other->child_create);
|
||||
|
||||
return memcmp(this_nonce.ptr, other_nonce.ptr,
|
||||
min(this_nonce.len, other_nonce.len)) < 0;
|
||||
return chunk_compare_prefix(this_nonce, other_nonce) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1493,8 +1493,7 @@ METHOD(task_t, destroy, void,
|
||||
METHOD(ike_init_t, get_lower_nonce, chunk_t,
|
||||
private_ike_init_t *this)
|
||||
{
|
||||
if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
|
||||
min(this->my_nonce.len, this->other_nonce.len)) < 0)
|
||||
if (chunk_compare_prefix(this->my_nonce, this->other_nonce) < 0)
|
||||
{
|
||||
return this->my_nonce;
|
||||
}
|
||||
|
||||
@@ -582,8 +582,7 @@ static bool collision_lost(private_ike_rekey_t *this, bool multi_ke)
|
||||
|
||||
/* the SA with the lowest nonce should be deleted (if already complete),
|
||||
* check if we or the peer created that */
|
||||
if (memcmp(this_nonce.ptr, other_nonce.ptr,
|
||||
min(this_nonce.len, other_nonce.len)) < 0)
|
||||
if (chunk_compare_prefix(this_nonce, other_nonce) < 0)
|
||||
{
|
||||
if (multi_ke)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user