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

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