summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2020-05-27 13:15:16 +0200
committerGitHub <noreply@github.com>2020-05-27 13:15:16 +0200
commitc4eae30a53a2996f5ae80a496b6ab161308f0b05 (patch)
tree4e4e23f77640c7343a53e3a23462ee5f301d07c4 /src/map
parent787e5996c7bb25fb33104d63ee4520994f1aa563 (diff)
parent0c37ea01658baaf16a82d8125484eeb03f4c6999 (diff)
downloadhercules-c4eae30a53a2996f5ae80a496b6ab161308f0b05.tar.gz
hercules-c4eae30a53a2996f5ae80a496b6ab161308f0b05.tar.bz2
hercules-c4eae30a53a2996f5ae80a496b6ab161308f0b05.tar.xz
hercules-c4eae30a53a2996f5ae80a496b6ab161308f0b05.zip
Merge pull request #2721 from Kenpachi2k13/whisper_name_length
Enable receiving not NULL terminated whisper names with a length of 24 characters
Diffstat (limited to 'src/map')
-rw-r--r--src/map/clif.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index ab13ffe1f..a0ec1fdf6 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10389,7 +10389,8 @@ static const char *clif_process_chat_message(struct map_session_data *sd, const
* @param[in] sd The source character.
* @param[in] packet The packet data.
* @param[out] out_name The parsed target name buffer (must be a valid
- * buffer of size NAME_LENGTH).
+ * buffer of size NAME_LENGTH + 1 because the client
+ * can send 24 characters without NULL terminator).
* @param[out] out_message The output message buffer (must be a valid buffer).
* @param[in] out_messagelen The size of out_message.
* @retval true if the validation succeeded and the message is a chat message.
@@ -10399,7 +10400,7 @@ static const char *clif_process_chat_message(struct map_session_data *sd, const
*/
static bool clif_process_whisper_message(struct map_session_data *sd, const struct packet_whisper_message *packet, char *out_name, char *out_message, int out_messagelen)
{
- int namelen = 0, messagelen = 0;
+ int messagelen = 0;
nullpo_retr(false, sd);
nullpo_retr(false, packet);
@@ -10412,15 +10413,6 @@ static bool clif_process_whisper_message(struct map_session_data *sd, const stru
return false;
}
- // validate name
- namelen = (int)strnlen(packet->name, NAME_LENGTH-1); // name length (w/o zero byte)
-
- if (packet->name[namelen] != '\0') {
- // only restriction is that the name must be zero-terminated
- ShowWarning("clif_process_whisper_message: Player '%s' sent an unterminated name!\n", sd->status.name);
- return false;
- }
-
#if PACKETVER >= 20151001
// Packet doesn't include a NUL terminator
messagelen = packet->packet_len - NAME_LENGTH - 4;
@@ -10439,7 +10431,7 @@ static bool clif_process_whisper_message(struct map_session_data *sd, const stru
return false;
}
- safestrncpy(out_name, packet->name, namelen+1); // [!] packet->name is not NUL terminated
+ safestrncpy(out_name, packet->name, NAME_LENGTH + 1); // [!] packet->name is not NUL terminated
safestrncpy(out_message, packet->message, messagelen+1); // [!] packet->message is not necessarily NUL terminated
if (!pc->process_chat_message(sd, out_message))
@@ -11778,7 +11770,8 @@ static void clif_parse_WisMessage(int fd, struct map_session_data *sd)
struct map_session_data* dstsd;
int i;
- char target[NAME_LENGTH], message[CHAT_SIZE_MAX + 1];
+ char target[NAME_LENGTH + 1]; // Client can send 24 characters without NULL terminator.
+ char message[CHAT_SIZE_MAX + 1];
const struct packet_whisper_message *packet = RP2PTR(fd);
if (!clif->process_whisper_message(sd, packet, target, message, sizeof message))