From cf487818766ad03f24f63522bebad11f1b8dd960 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 --- .../glue/standalone/nsGREDirServiceProvider.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xpcom/glue/standalone/nsGREDirServiceProvider.cpp b/xpcom/glue/standalone/nsGREDirServiceProvider.cpp index 76960415956c..ccba8bce684b 100644 --- a/xpcom/glue/standalone/nsGREDirServiceProvider.cpp +++ b/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)