From 9f66580d7e353b96690690f776d557f1c9028b37 Mon Sep 17 00:00:00 2001 From: polaris- Date: Wed, 21 Oct 2015 06:49:49 -0400 Subject: [PATCH] Fix buffer overflow comments --- src/core/gdbstub/gdbstub.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 15e6f36a0..0d586ca10 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -306,6 +306,7 @@ static void SendReply(const char* reply) { command_length = strlen(reply); if (command_length + 4 > sizeof(command_buffer)) { LOG_ERROR(Debug_GDBStub, "command_buffer overflow in SendReply"); + return; } memcpy(command_buffer + 1, reply, command_length); @@ -403,12 +404,12 @@ static void ReadCommand() { } while ((c = ReadByte()) != GDB_STUB_END) { - command_buffer[command_length++] = c; - if (command_length == sizeof(command_buffer)) { + if (command_length >= sizeof(command_buffer)) { LOG_ERROR(Debug_GDBStub, "gdb: command_buffer overflow\n"); SendPacket(GDB_STUB_NACK); return; } + command_buffer[command_length++] = c; } u8 checksum_received = HexCharToValue(ReadByte()) << 4;