From f4258c56f5eae1b345820834209658476ea2beb4 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 16 Feb 2021 14:43:52 +0100 Subject: [PATCH] ike-sa-manager: Ensure we were able to create a new IKE_SA This may happen if we are unable to allocate an SPI. --- src/libcharon/sa/ike_sa_manager.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libcharon/sa/ike_sa_manager.c b/src/libcharon/sa/ike_sa_manager.c index 9fec03348..b6321cf16 100644 --- a/src/libcharon/sa/ike_sa_manager.c +++ b/src/libcharon/sa/ike_sa_manager.c @@ -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);