]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
image: Sanitize paths on *all* images rather than images loaded from Q3 shaders
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 11 Apr 2021 19:23:23 +0000 (19:23 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 11 Apr 2021 19:23:23 +0000 (19:23 +0000)
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
fs.h
image.c
model_shared.c

diff --git a/fs.c b/fs.c
index 87c5df4accacaa479f96ab0e2ebf5e4ca565fa84..182d05f3ef55eb04d624e15d72a43ea457095232 100644 (file)
--- 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 5977f8c6087a2e968bf6c5db4ef9c2f8db01079e..b8ada8b990b831b04c55441845e96958da262d59 100644 (file)
--- 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 9f07ce60f174a955f89474114062eb19bb8358eb..ed498ed6562ce832080410a4fc25a9378aeb4727 100644 (file)
--- 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;
index 3213a050f8a015f6d195dafc91a5415852c6d2ed..f4a1a1116b70eb8bc38a2d8a962a2e9c29405c23 100644 (file)
@@ -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;
 }