Tweak Sanitizer
This commit is contained in:
parent
c36f89e523
commit
19f8228058
@ -36,7 +36,7 @@ extern "C" {
|
|||||||
__attribute__((__used__)) return_type name args
|
__attribute__((__used__)) return_type name args
|
||||||
|
|
||||||
// Sanitize String
|
// Sanitize String
|
||||||
void sanitize_string(char **str, int max_length);
|
void sanitize_string(char **str, int max_length, unsigned int allow_newlines);
|
||||||
|
|
||||||
// Patching Functions
|
// Patching Functions
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ void _patch_address(const char *file, int line, void *start, void *target) {
|
|||||||
// Sanitize String
|
// Sanitize String
|
||||||
#define MINIMUM_MESSAGE_CHARACTER 32
|
#define MINIMUM_MESSAGE_CHARACTER 32
|
||||||
#define MAXIMUM_MESSAGE_CHARACTER 126
|
#define MAXIMUM_MESSAGE_CHARACTER 126
|
||||||
void sanitize_string(char **str, int max_length) {
|
void sanitize_string(char **str, int max_length, unsigned int allow_newlines) {
|
||||||
// Store Message Length
|
// Store Message Length
|
||||||
int length = strlen(*str);
|
int length = strlen(*str);
|
||||||
// Truncate Message
|
// Truncate Message
|
||||||
@ -224,6 +224,9 @@ void sanitize_string(char **str, int max_length) {
|
|||||||
}
|
}
|
||||||
// Loop Through Message
|
// Loop Through Message
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (allow_newlines && ((*str)[i] == '\n' || (*str)[i] == '\r')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ((*str)[i] < MINIMUM_MESSAGE_CHARACTER || (*str)[i] > MAXIMUM_MESSAGE_CHARACTER) {
|
if ((*str)[i] < MINIMUM_MESSAGE_CHARACTER || (*str)[i] > MAXIMUM_MESSAGE_CHARACTER) {
|
||||||
// Replace Illegal Character
|
// Replace Illegal Character
|
||||||
(*str)[i] = '?';
|
(*str)[i] = '?';
|
||||||
|
@ -39,7 +39,7 @@ static void send_message(unsigned char *server_side_network_handler, char *usern
|
|||||||
char *full_message = NULL;
|
char *full_message = NULL;
|
||||||
asprintf(&full_message, "<%s> %s", username, message);
|
asprintf(&full_message, "<%s> %s", username, message);
|
||||||
ALLOC_CHECK(full_message);
|
ALLOC_CHECK(full_message);
|
||||||
sanitize_string(&full_message, MAX_CHAT_MESSAGE_LENGTH);
|
sanitize_string(&full_message, MAX_CHAT_MESSAGE_LENGTH, 0);
|
||||||
(*ServerSideNetworkHandler_displayGameMessage)(server_side_network_handler, std::string(full_message));
|
(*ServerSideNetworkHandler_displayGameMessage)(server_side_network_handler, std::string(full_message));
|
||||||
free(full_message);
|
free(full_message);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ static void Gui_addMessage_injection(unsigned char *gui, std::string const& text
|
|||||||
// Sanitize Message
|
// Sanitize Message
|
||||||
char *new_message = strdup(text.c_str());
|
char *new_message = strdup(text.c_str());
|
||||||
ALLOC_CHECK(new_message);
|
ALLOC_CHECK(new_message);
|
||||||
sanitize_string(&new_message, -1);
|
sanitize_string(&new_message, -1, 1);
|
||||||
|
|
||||||
// Process Message
|
// Process Message
|
||||||
if (!Gui_addMessage_recursing) {
|
if (!Gui_addMessage_recursing) {
|
||||||
|
Loading…
Reference in New Issue
Block a user