From 444c9dcf41fc3c9fcd358abb29da776ca659dd01 Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Mon, 11 Oct 2021 10:45:02 -0400 Subject: [PATCH] * BugFix: Correct non-constant array allocations in the POSIX case insensitivity code. --- Engine/source/platformPOSIX/posixVolume.cpp | 14 +++++++++----- Engine/source/platformX86UNIX/x86UNIXFileio.cpp | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Engine/source/platformPOSIX/posixVolume.cpp b/Engine/source/platformPOSIX/posixVolume.cpp index 411559ffa..b8b070217 100644 --- a/Engine/source/platformPOSIX/posixVolume.cpp +++ b/Engine/source/platformPOSIX/posixVolume.cpp @@ -157,7 +157,7 @@ FileNodeRef PosixFileSystem::resolve(const Path& path) #ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE // Resolve the case sensitive filepath String::SizeType fileLength = file.length(); - UTF8 caseSensitivePath[fileLength + 1]; + UTF8* caseSensitivePath = new UTF8[fileLength + 1]; dMemcpy(caseSensitivePath, file.c_str(), fileLength); caseSensitivePath[fileLength] = 0x00; ResolvePathCaseInsensitive(caseSensitivePath, fileLength); @@ -167,17 +167,21 @@ FileNodeRef PosixFileSystem::resolve(const Path& path) String caseSensitiveFile = file; #endif + FileNodeRef result = 0; if (stat(caseSensitiveFile.c_str(),&info) == 0) { // Construct the appropriate object if (S_ISREG(info.st_mode)) - return new PosixFile(path,caseSensitiveFile); + result = new PosixFile(path,caseSensitiveFile); if (S_ISDIR(info.st_mode)) - return new PosixDirectory(path,caseSensitiveFile); + result = new PosixDirectory(path,caseSensitiveFile); } - - return 0; + +#ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE + delete[] caseSensitivePath; +#endif + return result; } FileNodeRef PosixFileSystem::create(const Path& path, FileNode::Mode mode) diff --git a/Engine/source/platformX86UNIX/x86UNIXFileio.cpp b/Engine/source/platformX86UNIX/x86UNIXFileio.cpp index 26a43ee7e..9669638ae 100644 --- a/Engine/source/platformX86UNIX/x86UNIXFileio.cpp +++ b/Engine/source/platformX86UNIX/x86UNIXFileio.cpp @@ -1286,7 +1286,7 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite) { #ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE dsize_t pathLength = dStrlen(path); - char caseSensitivePath[pathLength + 1]; + char* caseSensitivePath = new char[pathLength + 1]; // Load path into temporary buffer dMemcpy(caseSensitivePath, path, pathLength); @@ -1298,6 +1298,10 @@ bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite) bool retVal = recurseDumpDirectories(caseSensitivePath, "", directoryVector, -1, depth, noBasePath); clearExcludedDirectories(); + +#ifdef TORQUE_POSIX_PATH_CASE_INSENSITIVE + delete[] caseSensitivePath; +#endif return retVal; }