Skip to content

Commit 2ca2781

Browse files
committed
reallocate tmp buffer with space for null terminator
1 parent 8b7b675 commit 2ca2781

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

examples/ocsp_responder/ocsp_responder.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ static int LoadFile(const char* filename, byte** buf, word32* bufSz, int* isPem)
177177

178178
/* Check if PEM format by looking for -----BEGIN */
179179
if (isPem) {
180+
/* Reallocate with space for null terminator for XSTRSTR */
181+
byte* tmp = (byte*)XREALLOC(*buf, (word32)sz + 1, NULL,
182+
DYNAMIC_TYPE_TMP_BUFFER);
183+
if (tmp == NULL) {
184+
XFREE(*buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
185+
*buf = NULL;
186+
return MEMORY_E;
187+
}
188+
*buf = tmp;
189+
(*buf)[sz] = '\0';
180190
*isPem = (XSTRSTR((char*)*buf, "-----BEGIN") != NULL) ? 1 : 0;
181191
}
182192

0 commit comments

Comments
 (0)