From 2ca2781756f81c4bd1f2fa68a66e0864e7b3fbad Mon Sep 17 00:00:00 2001 From: Ruby Martin Date: Fri, 13 Mar 2026 17:28:00 -0600 Subject: [PATCH] reallocate tmp buffer with space for null terminator --- examples/ocsp_responder/ocsp_responder.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/ocsp_responder/ocsp_responder.c b/examples/ocsp_responder/ocsp_responder.c index e18ce1470a..dcf9658a71 100644 --- a/examples/ocsp_responder/ocsp_responder.c +++ b/examples/ocsp_responder/ocsp_responder.c @@ -177,6 +177,16 @@ static int LoadFile(const char* filename, byte** buf, word32* bufSz, int* isPem) /* Check if PEM format by looking for -----BEGIN */ if (isPem) { + /* Reallocate with space for null terminator for XSTRSTR */ + byte* tmp = (byte*)XREALLOC(*buf, (word32)sz + 1, NULL, + DYNAMIC_TYPE_TMP_BUFFER); + if (tmp == NULL) { + XFREE(*buf, NULL, DYNAMIC_TYPE_TMP_BUFFER); + *buf = NULL; + return MEMORY_E; + } + *buf = tmp; + (*buf)[sz] = '\0'; *isPem = (XSTRSTR((char*)*buf, "-----BEGIN") != NULL) ? 1 : 0; }