From 90b52acae18c0f4aa616f0e21c7059b175bb1fb5 Mon Sep 17 00:00:00 2001 From: Sryder Date: Sun, 18 Nov 2018 11:05:05 +0000 Subject: [PATCH] Fix potential warning from string truncation Also the MS seems to just throw the entire char array into the website and ignore null terminators, so I'm memsetting maptitle all to 0 before we do anything with it. --- src/d_clisrv.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f1def1c61..29b3c0db6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1320,6 +1320,8 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) else netbuffer->u.serverinfo.iszone = 0; + memset(netbuffer->u.serverinfo.maptitle, 0, 33); + if (!(mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU) && mapheaderinfo[gamemap-1]->lvlttl[0]) { //strncpy(netbuffer->u.serverinfo.maptitle, (char *)mapheaderinfo[gamemap-1]->lvlttl, 33); @@ -1340,15 +1342,27 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) else { if (mapheaderinfo[gamemap-1]->actnum[0]) - snprintf(netbuffer->u.serverinfo.maptitle, + { + if (snprintf(netbuffer->u.serverinfo.maptitle, 33, "%s %s %s", - mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum); + mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl, mapheaderinfo[gamemap-1]->actnum) < 0) + { + // If there's an encoding error, send UNKNOWN, we accept that the above may be truncated + strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33); + } + } else - snprintf(netbuffer->u.serverinfo.maptitle, + { + if (snprintf(netbuffer->u.serverinfo.maptitle, 33, "%s %s", - mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl); + mapheaderinfo[gamemap-1]->lvlttl, mapheaderinfo[gamemap-1]->zonttl) < 0) + { + // If there's an encoding error, send UNKNOWN, we accept that the above may be truncated + strncpy(netbuffer->u.serverinfo.maptitle, "UNKNOWN", 33); + } + } } } else