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

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