diff options
author | Haru <haru@dotalux.com> | 2018-02-13 02:23:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-13 02:23:55 +0100 |
commit | b80b33c0f4a78d1c15829697a0fa8266ffa46623 (patch) | |
tree | 5b0b4efaa5798d57fcadc2654afff02a7ab50ba2 | |
parent | fa0591c15b0e821ba8c7901a3005c2674ae11796 (diff) | |
parent | 3c6f9eb913c643872f00fcd6d01bd3dc4c8b15fb (diff) | |
download | hercules-b80b33c0f4a78d1c15829697a0fa8266ffa46623.tar.gz hercules-b80b33c0f4a78d1c15829697a0fa8266ffa46623.tar.bz2 hercules-b80b33c0f4a78d1c15829697a0fa8266ffa46623.tar.xz hercules-b80b33c0f4a78d1c15829697a0fa8266ffa46623.zip |
Merge pull request #1973 from MishimaHaruna/bg_message-fix
Fix unterminated strings in ZC_BATTLEFIELD_CHAT
-rw-r--r-- | src/map/clif.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index 6e1cb4cf7..7c314b075 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -16566,18 +16566,15 @@ void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name return; len = (int)strlen(mes); -#if PACKETVER <= 20120716 - len += 1; -#endif - Assert_retv(len <= INT16_MAX - NAME_LENGTH - 8); - buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char)); - - WBUFW(buf,0) = 0x2dc; - WBUFW(buf,2) = len + NAME_LENGTH + 8; - WBUFL(buf,4) = src_id; - memcpy(WBUFP(buf,8), name, NAME_LENGTH); - memcpy(WBUFP(buf,32), mes, len); // [!] no NUL terminator - clif->send(buf,WBUFW(buf,2), &sd->bl, BG); + Assert_retv(len <= INT16_MAX - NAME_LENGTH - 9); + buf = (unsigned char *)aCalloc(len + NAME_LENGTH + 9, sizeof(unsigned char)); + + WBUFW(buf, 0) = 0x2dc; + WBUFW(buf, 2) = len + NAME_LENGTH + 9; + WBUFL(buf, 4) = src_id; + safestrncpy(WBUFP(buf, 8), name, NAME_LENGTH); + safestrncpy(WBUFP(buf, 32), mes, len + 1); + clif->send(buf, WBUFW(buf, 2), &sd->bl, BG); aFree(buf); } |