From c3b3b376fa85d8a5af1f2cc7d5f7cbc05d07e266 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 16 May 2015 14:27:01 +0000 Subject: [PATCH] config.c: fix an overlapping strcpy() in CONFIG_SetMapBestTime(). git-svn-id: https://svn.eduke32.com/eduke32@5193 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/config.c | 37 +++++++++++++++------------------ polymer/eduke32/source/config.h | 4 ++-- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 13ad88320..7fb01987c 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -983,46 +983,43 @@ void CONFIG_WriteSetup(uint32_t flags) Bfflush(NULL); } - -int32_t CONFIG_GetMapBestTime(char *mapname) +static const char *CONFIG_GetMapEntryName(char m[], const char *mapname) { - int32_t t = -1; - char m[BMAX_PATH], *p; - strcpy(m, mapname); - p = strrchr(m, '/'); + + char *p = strrchr(m, '/'); if (!p) p = strrchr(m, '\\'); - if (p) Bmemmove(m, p, Bstrlen(p)+1);//strcpy(m, p); + if (p) Bmemmove(m, p, Bstrlen(p)+1); for (p=m; *p; p++) *p = tolower(*p); // cheap hack because SCRIPT_GetNumber doesn't like the slashes p = m; while (*p == '/') p++; + return p; +} + +int32_t CONFIG_GetMapBestTime(const char *mapname) +{ if (!ud.config.setupread) return -1; if (ud.config.scripthandle < 0) return -1; + char m[BMAX_PATH]; + const char *p = CONFIG_GetMapEntryName(m, mapname); + + int32_t t = -1; SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t); return t; } -int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm) +int32_t CONFIG_SetMapBestTime(const char *mapname, int32_t tm) { - char m[BMAX_PATH], *p; - - strcpy(m, mapname); - p = strrchr(m, '/'); - if (!p) p = strrchr(m, '\\'); - if (p) strcpy(m, p); - for (p=m; *p; p++) *p = tolower(*p); - - // cheap hack because SCRIPT_GetNumber doesn't like the slashes - p = m; - while (*p == '/') p++; - if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename); if (ud.config.scripthandle < 0) return -1; + char m[BMAX_PATH]; + const char *p = CONFIG_GetMapEntryName(m, mapname); + SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", p, tm, FALSE, FALSE); return 0; } diff --git a/polymer/eduke32/source/config.h b/polymer/eduke32/source/config.h index eb1eda50d..c7ae19173 100644 --- a/polymer/eduke32/source/config.h +++ b/polymer/eduke32/source/config.h @@ -32,8 +32,8 @@ void CONFIG_SetupMouse( void ); void CONFIG_SetupJoystick( void ); void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN]); -int32_t CONFIG_GetMapBestTime(char *mapname); -int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm); +int32_t CONFIG_GetMapBestTime(const char *mapname); +int32_t CONFIG_SetMapBestTime(const char *mapname, int32_t tm); void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2);