On Mon, 24 Nov 2014, Jan Cholasta wrote:
From fef20b5966b4a49cc8c230437cf8f06899b51840 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Mon, 24 Nov 2014 13:57:10 +0000
Subject: [PATCH] Fix memory leak in GetKeytabControl asn1 code

https://fedorahosted.org/freeipa/ticket/4713
---
asn1/ipa_asn1.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/asn1/ipa_asn1.c b/asn1/ipa_asn1.c
index 50851a8..9efca96 100644
--- a/asn1/ipa_asn1.c
+++ b/asn1/ipa_asn1.c
@@ -77,12 +77,12 @@ bool ipaasn1_enc_getktreply(int kvno, struct keys_container 
*keys,
{
    GetKeytabControl_t gkctrl = { 0 };
    bool ret = false;
+    KrbKey_t *KK;

    gkctrl.present = GetKeytabControl_PR_reply;
    gkctrl.choice.reply.newkvno = kvno;

    for (int i = 0; i < keys->nkeys; i++) {
-        KrbKey_t *KK;
        KK = calloc(1, sizeof(KrbKey_t));
        if (!KK) goto done;
        KK->key.type = keys->ksdata[i].key.enctype;
@@ -109,9 +109,18 @@ bool ipaasn1_enc_getktreply(int kvno, struct 
keys_container *keys,
    }

    ret = encode_GetKeytabControl(&gkctrl, buf, len);
+    KK = NULL;

done:
    ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_GetKeytabControl, &gkctrl);
+    if (KK) {
+        free(KK->key.value.buf);
+        if (KK->salt) {
+            free(KK->salt->value.buf);
+            free(KK->salt);
+        }
+        free(KK);
+    }
    return ret;
}

ACK.

--
/ Alexander Bokovoy

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to