Tweak Sanitizer
minecraft-pi-reborn/pipeline/head This commit looks good Details

pull/10/head^2
TheBrokenRail 2 years ago
parent c36f89e523
commit 19f8228058

@ -36,7 +36,7 @@ extern "C" {
__attribute__((__used__)) return_type name args
// Sanitize String
void sanitize_string(char **str, int max_length);
void sanitize_string(char **str, int max_length, unsigned int allow_newlines);
// Patching Functions

@ -214,7 +214,7 @@ void _patch_address(const char *file, int line, void *start, void *target) {
// Sanitize String
#define MINIMUM_MESSAGE_CHARACTER 32
#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
int length = strlen(*str);
// Truncate Message
@ -224,6 +224,9 @@ void sanitize_string(char **str, int max_length) {
}
// Loop Through Message
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) {
// Replace Illegal Character
(*str)[i] = '?';

@ -39,7 +39,7 @@ static void send_message(unsigned char *server_side_network_handler, char *usern
char *full_message = NULL;
asprintf(&full_message, "<%s> %s", username, 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));
free(full_message);
}

@ -74,7 +74,7 @@ static void Gui_addMessage_injection(unsigned char *gui, std::string const& text
// Sanitize Message
char *new_message = strdup(text.c_str());
ALLOC_CHECK(new_message);
sanitize_string(&new_message, -1);
sanitize_string(&new_message, -1, 1);
// Process Message
if (!Gui_addMessage_recursing) {

Loading…
Cancel
Save