Add a return value to hasher_t.allocate_hash()
This commit is contained in:
@@ -78,7 +78,12 @@ static cert_payload_t *build_cert_payload(private_ike_cert_post_t *this,
|
||||
hasher->destroy(hasher);
|
||||
return NULL;
|
||||
}
|
||||
hasher->allocate_hash(hasher, encoded, &hash);
|
||||
if (!hasher->allocate_hash(hasher, encoded, &hash))
|
||||
{
|
||||
hasher->destroy(hasher);
|
||||
chunk_free(&encoded);
|
||||
return cert_payload_create_from_cert(CERTIFICATE, cert);
|
||||
}
|
||||
chunk_free(&encoded);
|
||||
hasher->destroy(hasher);
|
||||
id = identification_create_from_encoding(ID_KEY_ID, hash);
|
||||
|
||||
@@ -104,7 +104,10 @@ static chunk_t generate_natd_hash(private_ike_natd_t *this,
|
||||
|
||||
/* natd_hash = SHA1( spi_i | spi_r | address | port ) */
|
||||
natd_chunk = chunk_cat("cccc", spi_i_chunk, spi_r_chunk, addr_chunk, port_chunk);
|
||||
this->hasher->allocate_hash(this->hasher, natd_chunk, &natd_hash);
|
||||
if (!this->hasher->allocate_hash(this->hasher, natd_chunk, &natd_hash))
|
||||
{
|
||||
natd_hash = chunk_empty;
|
||||
}
|
||||
DBG3(DBG_IKE, "natd_chunk %B", &natd_chunk);
|
||||
DBG3(DBG_IKE, "natd_hash %B", &natd_hash);
|
||||
|
||||
@@ -152,6 +155,10 @@ static notify_payload_t *build_natd_payload(private_ike_natd_t *this,
|
||||
{
|
||||
hash = generate_natd_hash(this, ike_sa_id, host);
|
||||
}
|
||||
if (!hash.len)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
notify = notify_payload_create(NOTIFY);
|
||||
notify->set_notify_type(notify, type);
|
||||
notify->set_notification_data(notify, hash);
|
||||
@@ -298,7 +305,10 @@ METHOD(task_t, build_i, status_t,
|
||||
/* destination is always set */
|
||||
host = message->get_destination(message);
|
||||
notify = build_natd_payload(this, NAT_DETECTION_DESTINATION_IP, host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
|
||||
/* source may be any, we have 3 possibilities to get our source address:
|
||||
* 1. It is defined in the config => use the one of the IKE_SA
|
||||
@@ -309,7 +319,10 @@ METHOD(task_t, build_i, status_t,
|
||||
if (!host->is_anyaddr(host) || ike_cfg->force_encap(ike_cfg))
|
||||
{ /* 1. or if we force UDP encap, as it doesn't matter if it's %any */
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -319,7 +332,10 @@ METHOD(task_t, build_i, status_t,
|
||||
{ /* 2. */
|
||||
host->set_port(host, ike_cfg->get_my_port(ike_cfg));
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
host->destroy(host);
|
||||
}
|
||||
else
|
||||
@@ -333,7 +349,10 @@ METHOD(task_t, build_i, status_t,
|
||||
host->set_port(host, ike_cfg->get_my_port(ike_cfg));
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, host);
|
||||
host->destroy(host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
@@ -365,11 +384,16 @@ METHOD(task_t, build_r, status_t,
|
||||
/* initiator seems to support NAT detection, add response */
|
||||
me = message->get_source(message);
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, me);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
other = message->get_destination(message);
|
||||
notify = build_natd_payload(this, NAT_DETECTION_DESTINATION_IP, other);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user