ike-sa-manager: Ensure we were able to create a new IKE_SA
authorTobias Brunner <tobias@strongswan.org>
Tue, 16 Feb 2021 13:43:52 +0000 (14:43 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 16 Feb 2021 13:45:51 +0000 (14:45 +0100)
This may happen if we are unable to allocate an SPI.

src/libcharon/sa/ike_sa_manager.c

index 9fec033..b6321cf 100644 (file)
@@ -1501,8 +1501,11 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
        if (!this->reuse_ikesa && peer_cfg->get_ike_version(peer_cfg) != IKEV1)
        {       /* IKE_SA reuse disabled by config (not possible for IKEv1) */
                ike_sa = create_new(this, peer_cfg->get_ike_version(peer_cfg), TRUE);
-               ike_sa->set_peer_cfg(ike_sa, peer_cfg);
-               checkout_new(this, ike_sa);
+               if (ike_sa)
+               {
+                       ike_sa->set_peer_cfg(ike_sa, peer_cfg);
+                       checkout_new(this, ike_sa);
+               }
                charon->bus->set_sa(charon->bus, ike_sa);
                goto out;
        }
@@ -1573,8 +1576,11 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
        if (!ike_sa)
        {
                ike_sa = create_new(this, peer_cfg->get_ike_version(peer_cfg), TRUE);
-               ike_sa->set_peer_cfg(ike_sa, peer_cfg);
-               checkout_new(this, ike_sa);
+               if (ike_sa)
+               {
+                       ike_sa->set_peer_cfg(ike_sa, peer_cfg);
+                       checkout_new(this, ike_sa);
+               }
        }
        charon->bus->set_sa(charon->bus, ike_sa);