Skip to content

Commit b94dfe8

Browse files
Merge pull request #3335 from 4144/addchecks
Add validation to chat messages
2 parents 69edb0c + 9815693 commit b94dfe8

22 files changed

+2401
-2342
lines changed

src/common/HPMDataCheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of Hercules.
33
* http://herc.ws - http://github.com/HerculesWS/Hercules
44
*
5-
* Copyright (C) 2014-2024 Hercules Dev Team
5+
* Copyright (C) 2014-2025 Hercules Dev Team
66
*
77
* Hercules is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by

src/common/HPMSymbols.inc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of Hercules.
33
* http://herc.ws - http://github.com/HerculesWS/Hercules
44
*
5-
* Copyright (C) 2013-2024 Hercules Dev Team
5+
* Copyright (C) 2013-2025 Hercules Dev Team
66
*
77
* Hercules is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by

src/map/clif.c

+19
Original file line numberDiff line numberDiff line change
@@ -10755,6 +10755,19 @@ static void clif_msgtable_color(struct map_session_data *sd, enum clif_messages
1075510755
clif->send(&p, sizeof(p), &sd->bl, SELF);
1075610756
}
1075710757

10758+
static bool clif_validate_message(struct map_session_data *sd, char *message)
10759+
{
10760+
nullpo_retr(false, message);
10761+
10762+
if (strchr(message, '\n') != NULL ||
10763+
strchr(message, '\r') != NULL ||
10764+
strstr(message, " ") != NULL) {
10765+
return false;
10766+
}
10767+
10768+
return true;
10769+
}
10770+
1075810771
/**
1075910772
* Validates and processes a global/guild/party message packet.
1076010773
*
@@ -10819,6 +10832,8 @@ static const char *clif_process_chat_message(struct map_session_data *sd, const
1081910832
safestrncpy(out_buf, packet->message, textlen+1); // [!] packet->message is not necessarily NUL terminated
1082010833
message = out_buf + namelen + 3;
1082110834

10835+
if (clif->validate_message(sd, out_buf) == false)
10836+
return NULL;
1082210837
if (!pc->process_chat_message(sd, message))
1082310838
return NULL;
1082410839
return message;
@@ -10875,6 +10890,9 @@ static bool clif_process_whisper_message(struct map_session_data *sd, const stru
1087510890
safestrncpy(out_name, packet->name, NAME_LENGTH + 1); // [!] packet->name is not NUL terminated
1087610891
safestrncpy(out_message, packet->message, messagelen+1); // [!] packet->message is not necessarily NUL terminated
1087710892

10893+
if (clif->validate_message(sd, out_message) == false)
10894+
return false;
10895+
1087810896
if (!pc->process_chat_message(sd, out_message))
1087910897
return false;
1088010898

@@ -26883,6 +26901,7 @@ void clif_defaults(void)
2688326901
clif->messages = clif_displaymessage_sprintf;
2688426902
clif->process_chat_message = clif_process_chat_message;
2688526903
clif->process_whisper_message = clif_process_whisper_message;
26904+
clif->validate_message = clif_validate_message;
2688626905
clif->wisexin = clif_wisexin;
2688726906
clif->wisall = clif_wisall;
2688826907
clif->PMIgnoreList = clif_PMIgnoreList;

src/map/clif.h

+1
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ struct clif_interface {
12721272
void (*messages) (const int fd, const char *mes, ...) __attribute__((format(printf, 2, 3)));
12731273
const char *(*process_chat_message) (struct map_session_data *sd, const struct packet_chat_message *packet, char *out_buf, int out_buflen);
12741274
bool (*process_whisper_message) (struct map_session_data *sd, const struct packet_whisper_message *packet, char *out_name, char *out_message, int out_messagelen);
1275+
bool (*validate_message) (struct map_session_data *sd, char *message);
12751276
void (*wisexin) (struct map_session_data *sd,int type,int flag);
12761277
void (*wisall) (struct map_session_data *sd,int type,int flag);
12771278
void (*PMIgnoreList) (struct map_session_data* sd);

src/map/script.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -27026,7 +27026,12 @@ static BUILDIN(channelmes)
2702627026
return true;
2702727027
}
2702827028

27029-
channel->send(chan, NULL, script_getstr(st, 3));
27029+
char *message = script_getstr(st, 3);
27030+
if (clif->validate_message(sd, message) == false) {
27031+
script_pushint(st, 0);
27032+
return true;
27033+
}
27034+
channel->send(chan, NULL, message);
2703027035

2703127036
script_pushint(st, 1);
2703227037
return true;

src/plugins/HPMHooking/HPMHooking.Defs.inc

+585-583
Large diffs are not rendered by default.

src/plugins/HPMHooking/HPMHooking_api.HPMHooksCore.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of Hercules.
33
* http://herc.ws - http://github.com/HerculesWS/Hercules
44
*
5-
* Copyright (C) 2013-2024 Hercules Dev Team
5+
* Copyright (C) 2013-2025 Hercules Dev Team
66
*
77
* Hercules is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by

src/plugins/HPMHooking/HPMHooking_api.HookingPoints.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* This file is part of Hercules.
33
* http://herc.ws - http://github.com/HerculesWS/Hercules
44
*
5-
* Copyright (C) 2013-2024 Hercules Dev Team
5+
* Copyright (C) 2013-2025 Hercules Dev Team
66
*
77
* Hercules is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by

0 commit comments

Comments
 (0)