Blame SOURCES/0001-ensure_keytab_principals-do-not-leak-memory-when-cal.patch

f441eb
From 3a84c2469c31967bc22c0490456f07723ef5fc86 Mon Sep 17 00:00:00 2001
f441eb
From: Sumit Bose <sbose@redhat.com>
f441eb
Date: Wed, 20 Mar 2019 11:01:50 +0100
f441eb
Subject: [PATCH 1/4] ensure_keytab_principals: do not leak memory when called
f441eb
 twice
f441eb
f441eb
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1630187
f441eb
---
f441eb
 library/adenroll.c | 32 +++++++++++++++++++++-----------
f441eb
 1 file changed, 21 insertions(+), 11 deletions(-)
f441eb
f441eb
diff --git a/library/adenroll.c b/library/adenroll.c
f441eb
index d1f746c..48cb4cf 100644
f441eb
--- a/library/adenroll.c
f441eb
+++ b/library/adenroll.c
f441eb
@@ -413,6 +413,25 @@ ensure_service_principals (adcli_result res,
f441eb
 	return res;
f441eb
 }
f441eb
 
f441eb
+static void enroll_clear_keytab_principals (adcli_enroll *enroll)
f441eb
+{
f441eb
+	krb5_context k5;
f441eb
+	size_t c;
f441eb
+
f441eb
+	if (enroll->keytab_principals) {
f441eb
+		k5 = adcli_conn_get_krb5_context (enroll->conn);
f441eb
+		return_if_fail (k5 != NULL);
f441eb
+
f441eb
+		for (c = 0; enroll->keytab_principals[c] != NULL; c++)
f441eb
+			krb5_free_principal (k5, enroll->keytab_principals[c]);
f441eb
+
f441eb
+		free (enroll->keytab_principals);
f441eb
+		enroll->keytab_principals = NULL;
f441eb
+	}
f441eb
+
f441eb
+	return;
f441eb
+}
f441eb
+
f441eb
 static adcli_result
f441eb
 ensure_keytab_principals (adcli_result res,
f441eb
                           adcli_enroll *enroll)
f441eb
@@ -430,6 +449,7 @@ ensure_keytab_principals (adcli_result res,
f441eb
 	k5 = adcli_conn_get_krb5_context (enroll->conn);
f441eb
 	return_unexpected_if_fail (k5 != NULL);
f441eb
 
f441eb
+	enroll_clear_keytab_principals (enroll);
f441eb
 	enroll->keytab_principals = calloc (count + 3, sizeof (krb5_principal));
f441eb
 	return_unexpected_if_fail (enroll->keytab_principals != NULL);
f441eb
 	at = 0;
f441eb
@@ -1860,18 +1880,8 @@ static void
f441eb
 enroll_clear_state (adcli_enroll *enroll)
f441eb
 {
f441eb
 	krb5_context k5;
f441eb
-	int i;
f441eb
-
f441eb
-	if (enroll->keytab_principals) {
f441eb
-		k5 = adcli_conn_get_krb5_context (enroll->conn);
f441eb
-		return_if_fail (k5 != NULL);
f441eb
-
f441eb
-		for (i = 0; enroll->keytab_principals[i] != NULL; i++)
f441eb
-			krb5_free_principal (k5, enroll->keytab_principals[i]);
f441eb
 
f441eb
-		free (enroll->keytab_principals);
f441eb
-		enroll->keytab_principals = NULL;
f441eb
-	}
f441eb
+	enroll_clear_keytab_principals (enroll);
f441eb
 
f441eb
 	if (enroll->keytab) {
f441eb
 		k5 = adcli_conn_get_krb5_context (enroll->conn);
f441eb
-- 
f441eb
2.20.1
f441eb