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

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