From d99f1b934022f4483c1dec1ab74dfb1e4f4621ad Mon Sep 17 00:00:00 2001 From: def Date: Wed, 18 Nov 2020 14:31:05 +0100 Subject: [PATCH] Allow utf8 ban reasons (fixes #3329) --- src/base/system.c | 13 ------------- src/base/system.h | 12 ------------ src/engine/shared/network_conn.cpp | 7 ++----- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/base/system.c b/src/base/system.c index c8f29fbee..6cc508c08 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -2417,19 +2417,6 @@ char *str_trim_words(char *str, int words) return str; } -/* makes sure that the string only contains the characters between 32 and 127 */ -void str_sanitize_strong(char *str_in) -{ - unsigned char *str = (unsigned char *)str_in; - while(*str) - { - *str &= 0x7f; - if(*str < 32) - *str = 32; - str++; - } -} - /* makes sure that the string only contains the characters between 32 and 255 */ void str_sanitize_cc(char *str_in) { diff --git a/src/base/system.h b/src/base/system.h index a1967c5ef..7cbe0c94b 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1101,18 +1101,6 @@ int str_format(char *buffer, int buffer_size, const char *format, ...) */ char *str_trim_words(char *str, int words); -/* - Function: str_sanitize_strong - Replaces all characters below 32 and above 127 with whitespace. - - Parameters: - str - String to sanitize. - - Remarks: - - The strings are treated as zero-terminated strings. -*/ -void str_sanitize_strong(char *str); - /* Function: str_sanitize_cc Replaces all characters below 32 with whitespace. diff --git a/src/engine/shared/network_conn.cpp b/src/engine/shared/network_conn.cpp index dd39c6c3b..757e53563 100644 --- a/src/engine/shared/network_conn.cpp +++ b/src/engine/shared/network_conn.cpp @@ -294,11 +294,8 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_ if(pPacket->m_DataSize > 1) { // make sure to sanitize the error string form the other party - if(pPacket->m_DataSize < 128) - str_copy(aStr, (char *)&pPacket->m_aChunkData[1], pPacket->m_DataSize); - else - str_copy(aStr, (char *)&pPacket->m_aChunkData[1], sizeof(aStr)); - str_sanitize_strong(aStr); + str_utf8_copy(aStr, (char *)&pPacket->m_aChunkData[1], minimum(pPacket->m_DataSize, (int)sizeof(aStr))); + str_sanitize_cc(aStr); } if(!m_BlockCloseMsg)