Blame SOURCES/0002-service-avoid-crash-if-LDAP-connection-fails.patch

86624f
From d7089129b966df83f083cb56ee90f6b906971cb6 Mon Sep 17 00:00:00 2001
86624f
From: Sumit Bose <sbose@redhat.com>
86624f
Date: Tue, 1 Dec 2020 16:09:10 +0100
86624f
Subject: [PATCH 2/3] service: avoid crash if LDAP connection fails
86624f
86624f
There was always a chance for a crash if the connection to LDAP failed.
86624f
In the ldaps case a failed connection became more likely e.g. due to
86624f
failed certificate checks.
86624f
86624f
This patch avoids the crash and returns an error to the client cleanly.
86624f
86624f
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1826964
86624f
---
86624f
 po/POTFILES.in                | 1 +
86624f
 service/realm-disco-mscldap.c | 7 +++++++
86624f
 service/realm-disco-rootdse.c | 6 ++++++
86624f
 3 files changed, 14 insertions(+)
86624f
86624f
diff --git a/po/POTFILES.in b/po/POTFILES.in
86624f
index 2de67c8..140ed4c 100644
86624f
--- a/po/POTFILES.in
86624f
+++ b/po/POTFILES.in
86624f
@@ -1,6 +1,7 @@
86624f
 service/org.freedesktop.realmd.policy.in
86624f
 service/realm-command.c
86624f
 service/realm-disco-mscldap.c
86624f
+service/realm-disco-rootdse.c
86624f
 service/realm-example.c
86624f
 service/realm-ini-config.c
86624f
 service/realm-invocation.c
86624f
diff --git a/service/realm-disco-mscldap.c b/service/realm-disco-mscldap.c
86624f
index 2504904..003bb66 100644
86624f
--- a/service/realm-disco-mscldap.c
86624f
+++ b/service/realm-disco-mscldap.c
86624f
@@ -349,6 +349,13 @@ realm_disco_mscldap_async (GSocketAddress *address,
86624f
 	}
86624f
 
86624f
 	clo->source = realm_ldap_connect_anonymous (address, protocol, FALSE, cancellable);
86624f
+	if (clo->source == NULL) {
86624f
+		g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED,
86624f
+		                         _("Failed to setup LDAP connection"));
86624f
+		g_object_unref (task);
86624f
+		return;
86624f
+	}
86624f
+
86624f
 	g_source_set_callback (clo->source, (GSourceFunc)on_ldap_io,
86624f
 	                       g_object_ref (task), g_object_unref);
86624f
 	g_source_attach (clo->source, g_task_get_context (task));
86624f
diff --git a/service/realm-disco-rootdse.c b/service/realm-disco-rootdse.c
86624f
index 4ed19e5..d9b44b3 100644
86624f
--- a/service/realm-disco-rootdse.c
86624f
+++ b/service/realm-disco-rootdse.c
86624f
@@ -475,6 +475,12 @@ realm_disco_rootdse_async (GSocketAddress *address,
86624f
 
86624f
 	clo->source = realm_ldap_connect_anonymous (address, G_SOCKET_PROTOCOL_TCP,
86624f
 	                                            use_ldaps, cancellable);
86624f
+	if (clo->source == NULL) {
86624f
+		g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_CONNECTED,
86624f
+		                         _("Failed to setup LDAP connection"));
86624f
+		g_object_unref (task);
86624f
+		return;
86624f
+	}
86624f
 	g_source_set_callback (clo->source, (GSourceFunc)on_ldap_io,
86624f
 	                       g_object_ref (task), g_object_unref);
86624f
 	g_source_attach (clo->source, g_task_get_context (task));
86624f
-- 
86624f
2.28.0
86624f