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.
This commit is contained in:
YAMAMOTO Takashi 2021-01-27 17:14:03 +09:00 committed by Alin Jerpelea
parent 3b21cd9ceb
commit 87c876c1cc

View File

@ -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)
{