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)