Handle initiation of not supported IKE versions properly
[strongswan.git] / src / libcharon / sa / ikev2 / tasks / ike_rekey.c
index 2cfcdc1..c3c6cf0 100644 (file)
@@ -123,16 +123,20 @@ METHOD(task_t, process_i_delete, status_t,
 METHOD(task_t, build_i, status_t,
        private_ike_rekey_t *this, message_t *message)
 {
+       ike_version_t version;
        peer_cfg_t *peer_cfg;
        host_t *other_host;
 
        /* create new SA only on first try */
        if (this->new_sa == NULL)
        {
-               ike_version_t version = this->ike_sa->get_version(this->ike_sa);
+               version = this->ike_sa->get_version(this->ike_sa);
                this->new_sa = charon->ike_sa_manager->checkout_new(
                                                                                charon->ike_sa_manager, version, TRUE);
-
+               if (!this->new_sa)
+               {       /* shouldn't happen */
+                       return FAILED;
+               }
                peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
                other_host = this->ike_sa->get_other_host(this->ike_sa);
                this->new_sa->set_peer_cfg(this->new_sa, peer_cfg);
@@ -149,7 +153,6 @@ METHOD(task_t, process_r, status_t,
        private_ike_rekey_t *this, message_t *message)
 {
        enumerator_t *enumerator;
-       ike_version_t version;
        peer_cfg_t *peer_cfg;
        child_sa_t *child_sa;
 
@@ -177,9 +180,12 @@ METHOD(task_t, process_r, status_t,
        }
        enumerator->destroy(enumerator);
 
-       version = this->ike_sa->get_version(this->ike_sa);
        this->new_sa = charon->ike_sa_manager->checkout_new(charon->ike_sa_manager,
-                                                                                                               version, FALSE);
+                                                       this->ike_sa->get_version(this->ike_sa), FALSE);
+       if (!this->new_sa)
+       {       /* shouldn't happen */
+               return FAILED;
+       }
 
        peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
        this->new_sa->set_peer_cfg(this->new_sa, peer_cfg);