diff mbox series

[v2,10/39] gdbserver: fix read buffer overflow

Message ID 20220420065013.222816-11-npiggin@gmail.com
State New
Headers show
Series gdbserver multi-threaded debugging and POWER9/10 support | expand

Commit Message

Nicholas Piggin April 20, 2022, 6:49 a.m. UTC
buffer gets NUL terminated so read must return max of size - 1.

Reviewed-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 src/pdbgproxy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c
index 906ed2f6..4c6327fb 100644
--- a/src/pdbgproxy.c
+++ b/src/pdbgproxy.c
@@ -385,10 +385,10 @@  static void destroy_client(int dead_fd)
 
 static int read_from_client(int fd)
 {
-	char buffer[BUFFER_SIZE + 1];
+	char buffer[BUFFER_SIZE];
 	int nbytes;
 
-	nbytes = read(fd, buffer, sizeof(buffer));
+	nbytes = read(fd, buffer, sizeof(buffer) - 1);
 	if (nbytes < 0) {
 		perror(__FUNCTION__);
 		return -1;