krb5 commit: Fix preauth crash on memory exhaustion

[email protected] Mon, 5 Dec 2022 16:42:01 -0500 (EST)
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/7736144eb613f797dea57a44da33007a19602e5e
commit 7736144eb613f797dea57a44da33007a19602e5e
Author: ChenChen Zhou <[email protected]>
Date:   Sun Nov 27 22:24:24 2022 +0800

    Fix preauth crash on memory exhaustion
    
    In k5_preauth_request_context_init(), check the result of calloc().
    
    [[email protected]: rewrote commit message; added free() of reqctx on error]
    
    ticket: 9079 (new)

 src/lib/krb5/krb/preauth2.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/lib/krb5/krb/preauth2.c b/src/lib/krb5/krb/preauth2.c
index ffca476c2..32f35b761 100644
--- a/src/lib/krb5/krb/preauth2.c
+++ b/src/lib/krb5/krb/preauth2.c
@@ -263,6 +263,10 @@ k5_preauth_request_context_init(krb5_context context,
      * preauth context's array of handles. */
     for (count = 0; pctx->handles[count] != NULL; count++);
     reqctx->modreqs = calloc(count, sizeof(*reqctx->modreqs));
+    if (reqctx->modreqs == NULL) {
+        free(reqctx);
+        return;
+    }
     for (i = 0; i < count; i++) {
         h = pctx->handles[i];
         if (h->vt.request_init != NULL)