diff mbox series

[v2,09/38] gdbserver: fix read buffer overflow

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

Commit Message

Nicholas Piggin March 29, 2022, 3:49 p.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 906ed2f..4c6327f 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;