From 1a5b73909a665302cc0ec214c546e33cf565e777 Mon Sep 17 00:00:00 2001 From: Mark Olsen Date: Sun, 15 Oct 2006 19:31:24 +0000 Subject: [PATCH] Don't send random stack contents to the client with chunked downloads if the file size modulo is not 1024 or if the client requests an out of bounds block. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2411 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/server/sv_user.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/engine/server/sv_user.c b/engine/server/sv_user.c index 24e60f46d..8f9d9b55a 100644 --- a/engine/server/sv_user.c +++ b/engine/server/sv_user.c @@ -1489,14 +1489,22 @@ void SV_NextChunkedDownload(int chunknum) { #define CHUNKSIZE 1024 char buffer[1024]; + int i; + if (host_client->datagram.cursize + CHUNKSIZE+5+50 > host_client->datagram.maxsize) return; //choked! VFS_SEEK (host_client->download, chunknum*CHUNKSIZE); - VFS_READ (host_client->download, buffer, CHUNKSIZE); + i = VFS_READ (host_client->download, buffer, CHUNKSIZE); - MSG_WriteByte(&host_client->datagram, svc_download); - MSG_WriteLong(&host_client->datagram, chunknum); - SZ_Write(&host_client->datagram, buffer, CHUNKSIZE); + if (i > 0) + { + if (i != CHUNKSIZE) + bzero(buffer+i, CHUNKSIZE-i); + + MSG_WriteByte(&host_client->datagram, svc_download); + MSG_WriteLong(&host_client->datagram, chunknum); + SZ_Write(&host_client->datagram, buffer, CHUNKSIZE); + } } /*