From effa0c2ae396aac18d9b81c28337bd25c6be37f2 Mon Sep 17 00:00:00 2001 From: Jan Sikorski Date: Fri, 8 May 2020 11:08:25 +0200 Subject: [PATCH] Malloc redoBuff in reportMessage to prevent stack overflow --- MoltenVK/MoltenVK/Utility/MVKBaseObject.mm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MoltenVK/MoltenVK/Utility/MVKBaseObject.mm b/MoltenVK/MoltenVK/Utility/MVKBaseObject.mm index c43332a3..1789e785 100644 --- a/MoltenVK/MoltenVK/Utility/MVKBaseObject.mm +++ b/MoltenVK/MoltenVK/Utility/MVKBaseObject.mm @@ -119,10 +119,9 @@ void MVKBaseObject::reportMessage(MVKBaseObject* mvkObj, int aslLvl, const char* // If message is too big for original buffer, allocate a buffer big enough to hold it and // write the message out again. We only want to do this double writing if we have to. - // Create the redoBuff outside scope of if block to allow it to be referencable by pMessage later below. int redoBuffSize = (msgLen >= kOrigBuffSize) ? msgLen + 1 : 0; - char redoBuff[redoBuffSize]; - if (redoBuffSize > 0) { + char *redoBuff = NULL; + if (redoBuffSize > 0 && (redoBuff = (char *)malloc(redoBuffSize))) { pMessage = redoBuff; vsnprintf(redoBuff, redoBuffSize, format, redoArgs); } @@ -135,6 +134,8 @@ void MVKBaseObject::reportMessage(MVKBaseObject* mvkObj, int aslLvl, const char* // Broadcast the message to any Vulkan debug report callbacks if (hasDebugCallbacks) { mvkInst->debugReportMessage(mvkAPIObj, aslLvl, pMessage); } + + free(redoBuff); } VkResult MVKBaseObject::reportError(VkResult vkErr, const char* format, ...) {