From 9ce941048033d510058ee0d46fdbdee9d7429306 Mon Sep 17 00:00:00 2001 From: Jordy Ruiz Date: Sun, 30 Dec 2018 23:43:31 +0100 Subject: [PATCH] Sanitize gametypes with str_sanitize_filename --- src/base/system.c | 16 ++++++++++++++++ src/base/system.h | 13 +++++++++++++ src/game/client/components/menus_browser.cpp | 6 +++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/base/system.c b/src/base/system.c index bcab1771e..4ea45b45b 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -1793,6 +1793,22 @@ void str_sanitize(char *str_in) } } +/* removes all forbidden windows/unix characters in filenames*/ +char* str_sanitize_filename(char* aName) +{ + char *str = (char *)aName; + while(*str) + { + // replace forbidden characters with a whispace + if(*str == '/' || *str == '<' || *str == '>' || *str == ':' || *str == '"' + || *str == '/' || *str == '\\' || *str == '|' || *str == '?' || *str == '*') + *str = ' '; + str++; + } + str_clean_whitespaces(aName); + return aName; +} + /* removes leading and trailing spaces and limits the use of multiple spaces */ void str_clean_whitespaces(char *str_in) { diff --git a/src/base/system.h b/src/base/system.h index 3f842279e..26c9a2aa7 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -826,6 +826,19 @@ void str_sanitize_cc(char *str); */ void str_sanitize(char *str); +/* + Function: str_sanitize_filename + Replaces all forbidden Windows/Unix characters with whitespace + or nothing if leading or trailing. + + Parameters: + str - String to sanitize. + + Remarks: + - The strings are treated as zero-terminated strings. +*/ +char* str_sanitize_filename(char* aName); + /* Function: str_check_pathname Check if the string contains '..' (parent directory) paths. diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index ab942cc33..4c37fcef3 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -2132,11 +2132,15 @@ void CMenus::RenderServerbrowserBottomBox(CUIRect MainView) } void CMenus::DoGameIcon(const char *pName, const CUIRect *pRect, int Type) { + char aNameBuf[128]; + str_copy(aNameBuf, pName, sizeof(aNameBuf)); + str_sanitize_filename(aNameBuf); + // get texture IGraphics::CTextureHandle Tex = m_GameIconDefault; for(int i = 0; i < m_lGameIcons.size(); ++i) { - if(!str_comp_nocase(pName, m_lGameIcons[i].m_Name)) + if(!str_comp_nocase(aNameBuf, m_lGameIcons[i].m_Name)) { Tex = m_lGameIcons[i].m_IconTexture; break;