zturtleman / mm3d

Maverick Model 3D is a 3D model editor and animator for games.
https://clover.moe/mm3d
GNU General Public License v2.0
110 stars 22 forks source link

GetModuleFileNameA (Windows) can produce mutant paths that fail FindFirstFile (PathCanonicalize) #163

Closed m-7761 closed 2 years ago

m-7761 commented 2 years ago

https://github.com/zturtleman/mm3d/blob/0ddf1224e8facfb0d8d82ba1e5b518be01779a74/src/mm3dcore/sysconf.cc#L69

This is kind of stupid but I was trying to add some stuff to my MM3D project/work today, and ran into a situation where FindFirstFileA fails on the plugin directory tracked back to GetModuleFileNameA in sysconf.cc. What's happening is Visual Studio (2019?) uses $(TargetPath) that has a mix of forward/backward slashes and /../ patterns that don't seem to fly with FindFirstFileA, specifically getSharedPluginDirectory (MM3D).

I spot-fixed getExecutablePath (MM3D) for myself (see following code sample) but seeing as how either / or /../ is not allowed a more correct fix might be more extensive. If you dig deeper than I, I'm interested to see what you come up with.

std::string rval = "";
char execpath[MAX_PATH];
char execpath2[MAX_PATH];
DWORD length;

length = GetModuleFileNameA(nullptr,execpath2,sizeof(execpath));

//2021: Visual Studio generated paths fail FindFirstFile
if(PathCanonicalizeA(execpath,execpath2))
length = strlen(execpath);
zturtleman commented 2 years ago

Thanks. Fixed in 9fcc6a2ae927281f872973d2371032e2c28eb9f9.