From b30b2d519ee78739355019c6ee2df7ecaedededb Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Fri, 14 Jan 2005 00:00:56 +0000 Subject: [PATCH] fixes bug 278306 "Possible unexpected truncation of path in GRE_GetCurrentProcessDirectory" patch by callek, r+sr=darin git-svn-id: svn://10.0.0.236/trunk@167695 18797224-902f-48f8-a5cc-f745e15eee43 --- .../glue/standalone/nsGREDirServiceProvider.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp b/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp index 76960415956..ccba8bce684 100644 --- a/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp +++ b/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp @@ -52,6 +52,7 @@ #ifdef XP_WIN32 #include #include +#include #elif defined(XP_OS2) #define INCL_DOS #include @@ -131,13 +132,14 @@ GRE_GetCurrentProcessDirectory(char* buffer) *buffer = '\0'; #ifdef XP_WIN - if ( ::GetModuleFileName(0, buffer, MAXPATHLEN) ) { - // chop of the executable name by finding the rightmost backslash - char* lastSlash = PL_strrchr(buffer, '\\'); - if (lastSlash) { - *(lastSlash) = '\0'; - return PR_TRUE; - } + DWORD bufLength = ::GetModuleFileName(0, buffer, MAXPATHLEN); + if (bufLength == 0 || bufLength >= MAXPATHLEN) + return PR_FALSE; + // chop of the executable name by finding the rightmost backslash + unsigned char* lastSlash = _mbsrchr((unsigned char*) buffer, '\\'); + if (lastSlash) { + *(lastSlash) = '\0'; + return PR_TRUE; } #elif defined(XP_MACOSX)