From 93874226553d367642677ed67573035a5173800a Mon Sep 17 00:00:00 2001 From: In-line Date: Tue, 21 Feb 2017 02:18:45 +0400 Subject: [PATCH] Fix IsSafeFileToDownload (thx [WPMG]PRoSToTeM@) (#374) Fix nullptr dereferencing in IsSafeFileToDownload. --- rehlds/engine/sv_main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index e6d274a..a743f52 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -7327,7 +7327,10 @@ qboolean IsSafeFileToDownload(const char *filename) first = Q_strchr(lwrfilename, '.'); #ifdef REHLDS_FIXES - last = Q_strrchr(first, '.'); + if(first) + last = Q_strrchr(first, '.'); + else + last = nullptr; #else last = Q_strrchr(lwrfilename, '.'); #endif @@ -7335,9 +7338,11 @@ qboolean IsSafeFileToDownload(const char *filename) if (lwrfilename[0] == '/' || Q_strstr(lwrfilename, "\\") || Q_strstr(lwrfilename, ":") +#ifndef REHLDS_FIXES // Redundant check || Q_strstr(lwrfilename, "..") +#endif || Q_strstr(lwrfilename, "~") - || first != last + || first != last // This and below line make sure that dot count is always equal to one || !first || Q_strlen(first) != 4 || Q_strstr(lwrfilename, "halflife.wad") @@ -7353,8 +7358,8 @@ qboolean IsSafeFileToDownload(const char *filename) || Q_strcmp(first, ".dll") == 0 || Q_strcmp(first, ".ini") == 0 || Q_strcmp(first, ".log") == 0 -// || Q_strcmp(lwrfilename, ".so") == 0 // Extension length must be 4 to get here -// || Q_strcmp(lwrfilename, ".dylib") == 0 +// || Q_strcmp(first, ".so") == 0 // We can't get here, because of extension length check +// || Q_strcmp(first, ".dylib") == 0 || Q_strcmp(first, ".sys") == 0) #else || Q_strstr(lwrfilename, ".cfg")