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

Nicholas Piggin npiggin at gmail.com
Wed Apr 20 16:49:44 AEST 2022


buffer gets NUL terminated so read must return max of size - 1.

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

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;
-- 
2.35.1



More information about the Pdbg mailing list