From 6720daa07a037043de23d5ccb622c0d77cc86496 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Thu, 24 Dec 2015 21:25:06 -0600 Subject: [PATCH] Avoid a possible buffer overflow in winpty-debugserver.exe Also: use fwrite directly instead of printf; maybe it's a bit faster. --- src/debugserver/DebugServer.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/debugserver/DebugServer.cc b/src/debugserver/DebugServer.cc index 2e605aa..e20c8c8 100644 --- a/src/debugserver/DebugServer.cc +++ b/src/debugserver/DebugServer.cc @@ -37,7 +37,7 @@ int main() { 10 * 1000, NULL); - char msgBuffer[MSG_SIZE]; + char msgBuffer[MSG_SIZE + 1]; while (true) { if (!ConnectNamedPipe(serverPipe, NULL)) { @@ -52,8 +52,8 @@ int main() { DisconnectNamedPipe(serverPipe); continue; } - msgBuffer[bytesRead] = '\0'; - printf("%s\n", msgBuffer); + msgBuffer[bytesRead] = '\n'; + fwrite(msgBuffer, 1, bytesRead + 1, stdout); fflush(stdout); DWORD bytesWritten = 0;