Fix potential buffer overrun in error module.

errorInternalThrow() called strncpy(stackTraceBuffer, stackTrace, n - 1) followed by messageBuffer[n - 1] = '\0' -- a copy-paste bug that wrote the NUL terminator into the wrong buffer.

Since both buffers are ERROR_MESSAGE_BUFFER_SIZE the errant write was in-bounds and messageBuffer was already terminated, so the bug was silent in practice. But when stackTrace's length >= sizeof(stackTraceBuffer) - 1, strncpy() does not null-terminate, leaving stackTraceBuffer non-terminated and exposing errorContext.error.stackTrace to over-read by any consumer.
This commit is contained in:
Christophe Pettus
2026-06-17 12:22:42 +07:00
committed by David Steele
parent 5b77f9bc22
commit 7fd8bc89a1
2 changed files with 13 additions and 1 deletions
+11
View File
@@ -1,5 +1,16 @@
<release date="XXXX-XX-XX" version="2.59.0dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-bug-list>
<release-item>
<release-item-contributor-list>
<release-item-contributor id="christophe.pettus"/>
<release-item-reviewer id="david.steele"/>
</release-item-contributor-list>
<p>Fix potential buffer overrun in error module.</p>
</release-item>
</release-bug-list>
<release-feature-list>
<release-item>
<github-pull-request id="2779"/>
+2 -1
View File
@@ -387,8 +387,9 @@ errorInternalThrow(
// If a stack trace was provided
if (stackTrace != NULL)
{
// strncpy() does not null-terminate when the source length >= size, so force termination on stackTraceBuffer
strncpy(stackTraceBuffer, stackTrace, sizeof(stackTraceBuffer) - 1);
messageBuffer[sizeof(stackTraceBuffer) - 1] = '\0';
stackTraceBuffer[sizeof(stackTraceBuffer) - 1] = '\0';
}
// Else generate the stack trace for the error
else if (