From be39ca521067535ecd8c830f89380d4ea6b4834d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 6 Nov 2011 17:36:39 -0800 Subject: [PATCH 1/7] Fix some bugs in plStatusLog. Closes #99. --- .../PubUtilLib/plStatusLog/plStatusLog.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 096d4194..5df6ad41 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -90,6 +90,16 @@ plStatusLogMgr::plStatusLogMgr() fDrawer = nil; fLastLogChangeTime = 0; +#if HS_BUILD_FOR_WIN32 + SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE); +//#elif HS_BUILD_FOR_DARWIN +// Do some Mac specific thing here eventually +#else + wchar* temp = hsStringToWString(getenv("HOME")); + swprintf(fBasePath, MAX_PATH, L"%S/.cache/Uru Live", temp); + delete[] temp; +#endif + plFileUtils::ConcatFileName(fBasePath, L"log"); plFileUtils::EnsureFilePathExists(fBasePath); } @@ -820,7 +830,11 @@ bool plStatusLog::IPrintLineToFile( const char *line, UInt32 count ) strncat(buf, work, arrsize(work)); } - strncat(buf, line, arrsize(line)); + if (count < arrsize(buf) - strlen(buf)) { + strncat(buf, line, count); + } else { + strncat(buf, line, arrsize(buf) - strlen(buf)); + } if(!fEncryptMe ) { From 497aac7ab23cea79e72c5980ba978893a1686268 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sun, 20 Nov 2011 19:27:08 +0100 Subject: [PATCH 2/7] =?UTF-8?q?Fix=20buffer=20size=20check=20=E2=80=93=20p?= =?UTF-8?q?revious=20version=20could=20still=20overrun=20by=201=20or=202?= =?UTF-8?q?=20bytes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 5df6ad41..99ea3b44 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -830,10 +830,12 @@ bool plStatusLog::IPrintLineToFile( const char *line, UInt32 count ) strncat(buf, work, arrsize(work)); } - if (count < arrsize(buf) - strlen(buf)) { + size_t remaining = arrsize(buf) - strlen(buf) - 1; + if (!fEncryptMe) remaining -= 1; + if (count <= remaining) { strncat(buf, line, count); } else { - strncat(buf, line, arrsize(buf) - strlen(buf)); + strncat(buf, line, remaining); } if(!fEncryptMe ) From ea4ba5028ab3f050af36773b7f2d0cbf7840be03 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sun, 20 Nov 2011 19:28:08 +0100 Subject: [PATCH 3/7] Fix compilation: include proper header for SHGetSpecialFolderPathW(). --- Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 99ea3b44..bceb0d0b 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -73,6 +73,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #if HS_BUILD_FOR_UNIX #include #define MAX_PATH PATH_MAX +#elif HS_BUILD_FOR_WIN32 + #include #endif ////////////////////////////////////////////////////////////////////////////// From f49b04e7f07a092dfe18d0c5fe531e1b6a5f0b1e Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sun, 20 Nov 2011 19:29:00 +0100 Subject: [PATCH 4/7] =?UTF-8?q?Add=20missing=20=E2=80=9CUru=20Live?= =?UTF-8?q?=E2=80=9D=20in=20log=20file=20path.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index bceb0d0b..91b92efd 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -94,6 +94,7 @@ plStatusLogMgr::plStatusLogMgr() #if HS_BUILD_FOR_WIN32 SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE); + plFileUtils::ConcatFileName(fBasePath, L"Uru Live"); //#elif HS_BUILD_FOR_DARWIN // Do some Mac specific thing here eventually #else From 39a35f5fd34e206f3d7e2d628e04c1bd4f3d88e5 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sun, 20 Nov 2011 19:29:42 +0100 Subject: [PATCH 5/7] =?UTF-8?q?Change=20log=20folder=20name=20back=20from?= =?UTF-8?q?=20=E2=80=9Clog=E2=80=9D=20to=20the=20original=20=E2=80=9CLog?= =?UTF-8?q?=E2=80=9D=20for=20consistency=20with=20other=20logging=20facili?= =?UTF-8?q?ties=20that=20still=20use=20PathGetLogDirectory().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index 91b92efd..eea7463b 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -103,7 +103,7 @@ plStatusLogMgr::plStatusLogMgr() delete[] temp; #endif - plFileUtils::ConcatFileName(fBasePath, L"log"); + plFileUtils::ConcatFileName(fBasePath, L"Log"); plFileUtils::EnsureFilePathExists(fBasePath); } From 8ec36007c134ebe6dbf434f8277250816fc8782a Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sat, 26 Nov 2011 20:44:40 +0100 Subject: [PATCH 6/7] =?UTF-8?q?Don=E2=80=99t=20hardcode=20"Uru=20Live"=20b?= =?UTF-8?q?ut=20use=20ProductLongName().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replicates behavior of PathGetLogDirectory(). --- Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index eea7463b..f0a08e03 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -94,15 +94,15 @@ plStatusLogMgr::plStatusLogMgr() #if HS_BUILD_FOR_WIN32 SHGetSpecialFolderPathW(NULL, fBasePath, CSIDL_LOCAL_APPDATA, TRUE); - plFileUtils::ConcatFileName(fBasePath, L"Uru Live"); //#elif HS_BUILD_FOR_DARWIN // Do some Mac specific thing here eventually #else wchar* temp = hsStringToWString(getenv("HOME")); - swprintf(fBasePath, MAX_PATH, L"%S/.cache/Uru Live", temp); + swprintf(fBasePath, MAX_PATH, L"%S/.cache", temp); delete[] temp; #endif + plFileUtils::ConcatFileName(fBasePath, ProductLongName()); plFileUtils::ConcatFileName(fBasePath, L"Log"); plFileUtils::EnsureFilePathExists(fBasePath); } From bb98cf94ba83c9addc4e48d7ae7ac7aac524ac52 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Sat, 26 Nov 2011 20:57:00 +0100 Subject: [PATCH 7/7] =?UTF-8?q?Don=E2=80=99t=20crash=20on=20Linux=20if=20e?= =?UTF-8?q?nvironment=20variable=20HOME=20is=20not=20set.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp index f0a08e03..7740cabd 100644 --- a/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp +++ b/Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp @@ -97,7 +97,9 @@ plStatusLogMgr::plStatusLogMgr() //#elif HS_BUILD_FOR_DARWIN // Do some Mac specific thing here eventually #else - wchar* temp = hsStringToWString(getenv("HOME")); + const char* home = getenv("HOME"); + if (!home) home = ""; + wchar* temp = hsStringToWString(home); swprintf(fBasePath, MAX_PATH, L"%S/.cache", temp); delete[] temp; #endif