From e5f88887dfcb3eb36f9028b031fb6f932d7538be Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 8 Jul 2026 11:51:55 +0200 Subject: [PATCH] size check before allocating --- src/microhttpd/daemon.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index aa8c2d3e..fc606900 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -2470,21 +2470,21 @@ psk_gnutls_adapter (gnutls_session_t session, &app_psk, &app_psk_size)) return -1; + if (UINT_MAX < app_psk_size) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (daemon, + _ ("PSK authentication failed: PSK too long.\n")); +#endif + free (app_psk); + return -1; + } if (NULL == (key->data = gnutls_malloc (app_psk_size))) { #ifdef HAVE_MESSAGES MHD_DLOG (daemon, _ ("PSK authentication failed: gnutls_malloc failed to " \ "allocate memory.\n")); -#endif - free (app_psk); - return -1; - } - if (UINT_MAX < app_psk_size) - { -#ifdef HAVE_MESSAGES - MHD_DLOG (daemon, - _ ("PSK authentication failed: PSK too long.\n")); #endif free (app_psk); return -1;