From 38905cac4b67f0e4c4b0f59af9ea7474482f088e Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikhono@redhat.com>
Date: Mon, 27 May 2024 15:25:45 +0800
Subject: [PATCH] monitor: avoid NULL deref in monitor_service_shutdown()

Resolves: https://github.com/SSSD/sssd/issues/5598

Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/monitor/monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index f5f8fe9..b464a12 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -2107,7 +2107,7 @@ static void monitor_service_shutdown(struct mt_svc *svc)
 
     /* We must decrease the number of services when shutting down
      * a {socket,dbus}-activated service. */
-    ctx->num_services--;
+    if (ctx != NULL) ctx->num_services--;
 
     DEBUG(SSSDBG_TRACE_FUNC,
           "Unregistering service %s (%p)\n", svc->identity, svc);
-- 
2.33.0

