4402: Fix stack-buffer-overflow in Whisper (fixes #4400) r=heinrich5991 a=def-

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-11-28 01:36:18 +00:00 committed by GitHub
commit 33be69f0ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3866,7 +3866,9 @@ void CGameContext::Whisper(int ClientID, char *pStr)
while(1)
{
if(pStr[0] == '"')
{
break;
}
else if(pStr[0] == '\\')
{
if(pStr[1] == '\\')
@ -3875,21 +3877,27 @@ void CGameContext::Whisper(int ClientID, char *pStr)
pStr++; // skip due to escape
}
else if(pStr[0] == 0)
{
Error = 1;
break;
}
*pDst = *pStr;
pDst++;
pStr++;
}
// write null termination
*pDst = 0;
if(!Error)
{
// write null termination
*pDst = 0;
pStr++;
pStr++;
for(Victim = 0; Victim < MAX_CLIENTS; Victim++)
if(str_comp(pName, Server()->ClientName(Victim)) == 0)
break;
for(Victim = 0; Victim < MAX_CLIENTS; Victim++)
if(str_comp(pName, Server()->ClientName(Victim)) == 0)
break;
}
}
else
{