]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix gic_keytab crash on memory exhaustion 1275/head
authorChenChen Zhou <357726167@qq.com>
Sun, 27 Nov 2022 14:57:14 +0000 (22:57 +0800)
committerGreg Hudson <ghudson@mit.edu>
Mon, 5 Dec 2022 21:50:00 +0000 (16:50 -0500)
get_as_key_keytab() does not check the result of krb5_copy_keyblock(),
and dereferences a null pointer if it fails.  Remove the call and
steal the memory from kt_ent instead.

[ghudson@mit.edu: rewrote commit message; fixed comments]

ticket: 9080 (new)

src/lib/krb5/krb/gic_keytab.c

index b8b7c15069ec218b767ca5dda8e2a6d64e073ca1..f9baabbf90cab753b7f2053263d5c4b43057ecb3 100644 (file)
@@ -45,7 +45,6 @@ get_as_key_keytab(krb5_context context,
     krb5_keytab keytab = (krb5_keytab) gak_data;
     krb5_error_code ret;
     krb5_keytab_entry kt_ent;
-    krb5_keyblock *kt_key;
 
     /* We don't need the password from the responder to create the AS key. */
     if (as_key == NULL)
@@ -71,16 +70,13 @@ get_as_key_keytab(krb5_context context,
                                  etype, &kt_ent)))
         return(ret);
 
-    ret = krb5_copy_keyblock(context, &kt_ent.key, &kt_key);
-
-    /* again, krb5's memory management is lame... */
-
-    *as_key = *kt_key;
-    free(kt_key);
+    /* Steal the keyblock from kt_ent for the caller. */
+    *as_key = kt_ent.key;
+    memset(&kt_ent.key, 0, sizeof(kt_ent.key));
 
     (void) krb5_kt_free_entry(context, &kt_ent);
 
-    return(ret);
+    return 0;
 }
 
 /* Return the list of etypes available for client in keytab. */