From 7736144eb613f797dea57a44da33007a19602e5e Mon Sep 17 00:00:00 2001
From: ChenChen Zhou <357726167@qq.com>
Date: Sun, 27 Nov 2022 22:24:24 +0800
Subject: [PATCH] Fix preauth crash on memory exhaustion

In k5_preauth_request_context_init(), check the result of calloc().

[ghudson@mit.edu: 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)
-- 
2.32.0.windows.1

