From fa560ff48ce448aa63dd6c303d48f4d14218acf7 Mon Sep 17 00:00:00 2001 From: mary-dcouto Date: Thu, 2 Jun 2022 13:03:43 +0530 Subject: [PATCH] fix for the crash that occurs when the ztx is disabled, because the timer handles are null --- library/ziti.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/ziti.c b/library/ziti.c index 739492e4..84226ab0 100644 --- a/library/ziti.c +++ b/library/ziti.c @@ -367,6 +367,19 @@ static void ziti_start_internal(ziti_context ztx, void *init_req) { uv_prepare_start(ztx->reaper, grim_reaper); ziti_ctrl_get_version(&ztx->controller, version_cb, ztx); ziti_set_unauthenticated(ztx); + + // if the ztx is disabled, api_session_timer and service_refresh_timer will be null + ztx->api_session_timer = calloc(1, sizeof(uv_timer_t)); + uv_timer_init(ztx->loop, ztx->api_session_timer); + ztx->api_session_timer->data = ztx; + + ztx->service_refresh_timer = calloc(1, sizeof(uv_timer_t)); + uv_timer_init(ztx->loop, ztx->service_refresh_timer); + if (ztx->opts->refresh_interval == 0) { + uv_unref((uv_handle_t *) ztx->service_refresh_timer); + } + ztx->service_refresh_timer->data = ztx; + ziti_re_auth(ztx); } } @@ -1141,6 +1154,10 @@ void ziti_services_refresh(uv_timer_t *t) { ZTX_LOG(DEBUG, "service refresh stopped, outstanding auth queries"); return; } + if (!ztx->enabled) { + ZTX_LOG(DEBUG, "service refresh stopped, ztx is disabled"); + return; + } if (ztx->no_service_updates_api) { ziti_ctrl_get_services(&ztx->controller, update_services, ztx);