]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix trivial KDC memory leak with test KDB module 734/head
authorsashan <anedvedicky@gmail.com>
Tue, 20 Feb 2018 21:35:51 +0000 (22:35 +0100)
committerGreg Hudson <ghudson@mit.edu>
Mon, 26 Feb 2018 22:06:39 +0000 (17:06 -0500)
If a KDB module zeroes out the master key in its fetch_master_key()
method (as the test KDB module does), krb5_db_fetch_mkey() will copy
it, allocating one byte of memory for the contents.  The KDC will then
leak it on exit, as the length is zero.  Simplify master key
destruction using zapfree().

[ghudson@mit.edu: wrote commit message]

src/kdc/main.c

index e1ee3a94f16f7c228d45bf7b7db976c1af053bdd..96281ada3aecb080f506d415e01c7e885b525a33 100644 (file)
@@ -161,11 +161,7 @@ finish_realm(kdc_realm_t *rdp)
     if (rdp->realm_context) {
         if (rdp->realm_mprinc)
             krb5_free_principal(rdp->realm_context, rdp->realm_mprinc);
-        if (rdp->realm_mkey.length && rdp->realm_mkey.contents) {
-            /* XXX shouldn't memset be zap for safety? */
-            memset(rdp->realm_mkey.contents, 0, rdp->realm_mkey.length);
-            free(rdp->realm_mkey.contents);
-        }
+        zapfree(rdp->realm_mkey.contents, rdp->realm_mkey.length);
         krb5_db_fini(rdp->realm_context);
         if (rdp->realm_tgsprinc)
             krb5_free_principal(rdp->realm_context, rdp->realm_tgsprinc);