From 4d4a2943fbf4ab54530c3f81013e973c9c4c8ad2 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 3 Jul 2021 01:47:10 +0000 Subject: [PATCH] Refuse to autoupdate the engine when the binary looks like it has a revision number in its file name. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5943 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/sys_win.c | 20 +++++++++++++++++++ engine/common/sys_linux_threads.c | 32 ++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/engine/client/sys_win.c b/engine/client/sys_win.c index 67dc8b739..7aaee9cbc 100644 --- a/engine/client/sys_win.c +++ b/engine/client/sys_win.c @@ -2956,6 +2956,10 @@ qboolean Sys_SetUpdatedBinary(const char *newbinary) wchar_t enginebinarybackup[MAX_OSPATH+4]; size_t len; static qboolean alreadymoved = false; + + //update blocked via commandline. to be doubly sure its checked. + if (COM_CheckParm("-noupdate") || COM_CheckParm("--noupdate") || COM_CheckParm("-noautoupdate") || COM_CheckParm("--noautoupdate")) + return false; //windows is annoying. we can't delete a file that's in use (no orphaning) //we can normally rename it to something else before writing a new file with the original name. @@ -3001,10 +3005,26 @@ qboolean Sys_SetUpdatedBinary(const char *newbinary) } qboolean Sys_EngineMayUpdate(void) { + wchar_t enginebinaryw[MAX_OSPATH]; if (!COM_CheckParm("-allowupdate")) { + char enginebinary[MAX_OSPATH*4]; + char *s; if (revision_number(true) <= 0) return false; + + GetModuleFileNameW(NULL, enginebinaryw, countof(enginebinaryw)-1); + narrowen(enginebinary, sizeof(enginebinary), enginebinaryw); + //if there's 3 consecutive digits or digit.digit then assume the user is doing their own versioning, and disallow engine updates (unless they use the -allowupdate arg). + //(that or they ran one of our older builds directly) + s = COM_SkipPath(enginebinary); + while (*s) + { + if ( s[0] >= '0' && s[0] <= '9') + if ((s[1] >= '0' && s[1] <= '9') || s[1] == '.' || s[1] == '_' || s[1] == '-') + if ( s[2] >= '0' && s[2] <= '9') + return false; + } } //update blocked via commandline diff --git a/engine/common/sys_linux_threads.c b/engine/common/sys_linux_threads.c index 81d93f64b..4705a4817 100644 --- a/engine/common/sys_linux_threads.c +++ b/engine/common/sys_linux_threads.c @@ -540,9 +540,9 @@ qboolean Sys_SetUpdatedBinary(const char *newbinary) int i; struct stat src, dst; - //windows is annoying. we can't delete a file that's in use (no orphaning) - //we can normally rename it to something else before writing a new file with the original name. - //then delete the old file later (sadly only on reboot) + //update blocked via commandline. just in case. + if (COM_CheckParm("-noupdate") || COM_CheckParm("--noupdate") || COM_CheckParm("-noautoupdate") || COM_CheckParm("--noautoupdate")) + return false; //get the binary name i = readlink("/proc/self/exe", enginebinary, sizeof(enginebinary)-1); @@ -585,20 +585,34 @@ qboolean Sys_EngineMayUpdate(void) char enginebinary[MAX_OSPATH]; int len; - //if we can't get a revision number from our cflags then don't allow updates (unless forced on). - if (!COM_CheckParm("-allowupdate")) - if (revision_number(true)<=0) - return false; - //update blocked via commandline if (COM_CheckParm("-noupdate") || COM_CheckParm("--noupdate") || COM_CheckParm("-noautoupdate") || COM_CheckParm("--noautoupdate")) return false; - //check that we can actually do it. len = readlink("/proc/self/exe", enginebinary, sizeof(enginebinary)-1); if (len <= 0) return false; + + //if we can't get a revision number from our cflags then don't allow updates (unless forced on). + if (!COM_CheckParm("-allowupdate")) + { + char *s; + if (revision_number(true)<=0) + return false; + + //if there's 3 consecutive digits or digit.digit then assume the user is doing their own versioning, and disallow engine updates (unless they use the -allowupdate arg). + //(that or they ran one of our older builds directly) + s = COM_SkipPath(enginebinary); + while (*s) + { + if ( s[0] >= '0' && s[0] <= '9') + if ((s[1] >= '0' && s[1] <= '9') || s[1] == '.' || s[1] == '_' || s[1] == '-') + if ( s[2] >= '0' && s[2] <= '9') + return false; + } + } + enginebinary[len] = 0; if (access(enginebinary, R_OK|W_OK|X_OK) < 0) return false; //can't write it. don't try downloading updates.