From 784410e413bccc2fb44104f832b344c2396c37c0 Mon Sep 17 00:00:00 2001 From: Stephen Pohl Date: Tue, 7 Oct 2014 09:33:09 -0400 Subject: [PATCH] Bug 1078640: Sanitize path used to load XPCOM on OSX. r=smichaud --- xpcom/build/BinaryPath.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xpcom/build/BinaryPath.h b/xpcom/build/BinaryPath.h index 0173e2874ca..a6c86191947 100644 --- a/xpcom/build/BinaryPath.h +++ b/xpcom/build/BinaryPath.h @@ -56,13 +56,29 @@ private: return NS_ERROR_FAILURE; } + UInt8 tempBuffer[MAXPATHLEN]; nsresult rv; - if (CFURLGetFileSystemRepresentation(executableURL, false, (UInt8*)aResult, + if (CFURLGetFileSystemRepresentation(executableURL, false, tempBuffer, MAXPATHLEN)) { rv = NS_OK; } else { rv = NS_ERROR_FAILURE; } + + // Sanitize path in case the app was launched from Terminal via './firefox' + // for example. + size_t readPos = 0; + size_t writePos = 0; + while (tempBuffer[readPos] != '\0') { + if (tempBuffer[readPos] == '.' && tempBuffer[readPos + 1] == '/') { + readPos += 2; + } + aResult[writePos] = tempBuffer[readPos]; + readPos++; + writePos++; + } + aResult[writePos] = '\0'; + CFRelease(executableURL); return rv; }