From 8b6a72238c9e0686395f9849a9c00f8762f3a244 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sun, 11 Apr 2021 19:23:23 +0000 Subject: [PATCH] image: Sanitize paths on *all* images rather than images loaded from Q3 shaders Implemented FS_SanitizePath. Perhaps expand on this? Not really a clean way to do it that I can think of, but I can't see the harm in doing this for all filepaths. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13117 d7cf8633-e32d-0410-b094-e92efae38249 --- fs.c | 18 ++++++++++++++++++ fs.h | 1 + image.c | 3 +++ model_shared.c | 5 ----- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fs.c b/fs.c index 87c5df4a..182d05f3 100644 --- a/fs.c +++ b/fs.c @@ -2507,6 +2507,24 @@ int FS_CheckNastyPath (const char *path, qbool isgamedir) return false; } +/* +==================== +FS_SanitizePath + +Sanitize path (replace non-portable characters +with portable ones in-place, etc) +==================== +*/ +void FS_SanitizePath(char *path) +{ + int i, size; + + for(i = 0, size = strlen(path); i < size; i++) + { + if(path[i] == '\\') + path[i] = '/'; + } +} /* ==================== diff --git a/fs.h b/fs.h index 5977f8c6..b8ada8b9 100644 --- a/fs.h +++ b/fs.h @@ -85,6 +85,7 @@ void FS_Purge (qfile_t* file); const char *FS_FileWithoutPath (const char *in); const char *FS_FileExtension (const char *in); int FS_CheckNastyPath (const char *path, qbool isgamedir); +void FS_SanitizePath (char *path); extern const char *const fs_checkgamedir_missing; // "(missing)" const char *FS_CheckGameDir(const char *gamedir); // returns NULL if nasty, fs_checkgamedir_missing (exact pointer) if missing diff --git a/image.c b/image.c index 9f07ce60..ed498ed6 100644 --- a/image.c +++ b/image.c @@ -1084,6 +1084,9 @@ unsigned char *loadimagepixelsbgra (const char *filename, qbool complain, qbool for (format = firstformat;format->formatstring;format++) { dpsnprintf (name, sizeof(name), format->formatstring, basename); + + FS_SanitizePath(name); + if(FS_FileExists(name) && (f = FS_LoadFile(name, tempmempool, true, &filesize)) != NULL) { mymiplevel = miplevel ? *miplevel : 0; diff --git a/model_shared.c b/model_shared.c index 3213a050..f4a1a111 100644 --- a/model_shared.c +++ b/model_shared.c @@ -2257,12 +2257,7 @@ texture_shaderpass_t *Mod_CreateShaderPassFromQ3ShaderLayer(mempool_t *mempool, for (j = 0; j < Q3MAXTCMODS && layer->tcmods[j].tcmod != Q3TCMOD_NONE; j++) shaderpass->tcmods[j] = layer->tcmods[j]; for (j = 0; j < layer->numframes; j++) - { - for (int i = 0; layer->texturename[j][i]; i++) - if(layer->texturename[j][i] == '\\') - layer->texturename[j][i] = '/'; shaderpass->skinframes[j] = R_SkinFrame_LoadExternal(layer->texturename[j], texflags, false, true); - } return shaderpass; } -- 2.39.2