From fd80bd5e335b465cbaded1d0d2e5e2ef8b249cc1 Mon Sep 17 00:00:00 2001 From: Rodent Control Date: Sun, 2 Nov 2025 18:05:04 +0100 Subject: [PATCH] print only printable characters and \n on console This prevents players or servers from abusing the terminal using escape sequences, making it beep/flash (\a) etc. --- code/sys/sys_main.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index d7f5398336..238308599a 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -433,6 +433,24 @@ void Sys_AnsiColorPrint( const char *msg ) } } +/* +================= +Sys_ReplaceNonPrintableChars +================= +*/ +void Sys_ReplaceNonPrintableChars(char *str) +{ + char *p; + + for (p = str; *p != '\0'; p++) + { + if ( !isprint(*p) && *p != '\n' ) + { + *p = '.'; + } + } +} + /* ================= Sys_Print @@ -440,8 +458,16 @@ Sys_Print */ void Sys_Print( const char *msg ) { - CON_LogWrite( msg ); - CON_Print( msg ); + char clean_msg[ MAXPRINTMSG ]; + + // Replace non-printable characters before we print the string + // Prevents abuse, e.g. players messing up the terminal by \say-ing + // escape sequences + Q_strncpyz(clean_msg, msg, sizeof(clean_msg)); + Sys_ReplaceNonPrintableChars(clean_msg); + + CON_LogWrite( clean_msg ); + CON_Print( clean_msg ); } /*