From 87c876c1cc7e79075130567150265207d261d212 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 27 Jan 2021 17:14:03 +0900 Subject: [PATCH] netcat: Fix a buffer overflow The buffer doesn't have the space for the terminating NUL. Fix it by replacing it with fwrite, as there seems to be little reason to use fprintf and NUL-terminated string in the first place. --- netutils/netcat/netcat_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netutils/netcat/netcat_main.c b/netutils/netcat/netcat_main.c index 575dd51d8..a6d4073f2 100644 --- a/netutils/netcat/netcat_main.c +++ b/netutils/netcat/netcat_main.c @@ -99,8 +99,7 @@ int netcat_server(int argc, char * argv[]) while (0 < avail) { avail = recv(conn, buf, capacity, 0); - buf[avail] = 0; - fprintf(fout, "%s", buf); + fwrite(buf, avail, 1, fout); int status = fflush(fout); if (0 != status) {