From 75b1fe68433a5b6276fe5da38e004b863710f335 Mon Sep 17 00:00:00 2001
From: Alexey Tikhonov <atikhono@redhat.com>
Date: Fri, 18 Oct 2019 19:55:27 +0200
Subject: [PATCH] sssctl/sssctl_domains.c: null dereference fixed
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Resolves: https://pagure.io/SSSD/sssd/issue/4102

Reviewed-by: Michal Židek <mzidek@redhat.com>
---
 src/tools/sssctl/sssctl_domains.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/tools/sssctl/sssctl_domains.c b/src/tools/sssctl/sssctl_domains.c
index 8b8df565b..026ac0710 100644
--- a/src/tools/sssctl/sssctl_domains.c
+++ b/src/tools/sssctl/sssctl_domains.c
@@ -209,6 +209,12 @@ sssctl_domain_status_active_server(struct sbus_sync_connection *conn,
         goto done;
     }
 
+    if (services == NULL) {
+        PRINT("This domain has no active servers.\n");
+        ret = EOK;
+        goto done;
+    }
+
     PRINT("Active servers:\n");
     for (i = 0; services[i] != NULL; i++) {
         ret = sbus_call_ifp_domain_ActiveServer(tmp_ctx, conn, IFP_BUS,
@@ -220,6 +226,7 @@ sssctl_domain_status_active_server(struct sbus_sync_connection *conn,
             goto done;
         }
 
+        /* SBUS_REQ_STRING_DEFAULT handles (server == NULL) case gracefully */
         server = SBUS_REQ_STRING_DEFAULT(server, _("not connected"));
         printf("%s: %s\n", proper_service_name(services[i]), server);
     }
@@ -256,6 +263,12 @@ sssctl_domain_status_server_list(struct sbus_sync_connection *conn,
         goto done;
     }
 
+    if (services == NULL) {
+        PRINT("No servers discovered.\n");
+        ret = EOK;
+        goto done;
+    }
+
     for (i = 0; services[i] != NULL; i++) {
         PRINT("Discovered %s servers:\n", proper_service_name(services[i]));
 
-- 
2.33.0

