diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2018-06-13 19:48:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 19:48:24 +0200 |
commit | e6ebea25bea93eb4ec07cbd5003545c4805886a8 (patch) | |
tree | 37ca7650a577d7adc9c510a8a7bf5eb92d07a478 /src/pal | |
parent | b90d7e8e749c4c936712c0b8a8d915eb8732928f (diff) | |
download | coreclr-e6ebea25bea93eb4ec07cbd5003545c4805886a8.tar.gz coreclr-e6ebea25bea93eb4ec07cbd5003545c4805886a8.tar.bz2 coreclr-e6ebea25bea93eb4ec07cbd5003545c4805886a8.zip |
Fix allocation methods at few places in PAL (#18457)
In the utf8.cpp and process.cpp, PAL was incorectly using the
global new operator. This results in calling this operator's
definition in coreclr runtime, which is wrong. In the case
of the utf8 stuff, a customer has reported a crash happening
due to that when the path from which the PAL was initialized
contained chinese characters.
THe fix is to use InternalNew / InternalDelete functions instead.
Diffstat (limited to 'src/pal')
-rw-r--r-- | src/pal/src/include/pal/malloc.hpp | 16 | ||||
-rw-r--r-- | src/pal/src/locale/utf8.cpp | 23 | ||||
-rw-r--r-- | src/pal/src/thread/process.cpp | 4 |
3 files changed, 37 insertions, 6 deletions
diff --git a/src/pal/src/include/pal/malloc.hpp b/src/pal/src/include/pal/malloc.hpp index 9faf4273d9..580b6a916c 100644 --- a/src/pal/src/include/pal/malloc.hpp +++ b/src/pal/src/include/pal/malloc.hpp @@ -85,6 +85,14 @@ namespace CorUnix{ return new (pMem) T(); } + // 1 arg case. + template<class T, class A1> + T* InternalNew(A1 arg1) + { + INTERNAL_NEW_COMMON(); + return new (pMem) T(arg1); + } + // 2 args case. template<class T, class A1, class A2> T* InternalNew(A1 arg1, A2 arg2) @@ -93,6 +101,14 @@ namespace CorUnix{ return new (pMem) T(arg1, arg2); } + // 3 args case. + template<class T, class A1, class A2, class A3> + T* InternalNew(A1 arg1, A2 arg2, A3 arg3) + { + INTERNAL_NEW_COMMON(); + return new (pMem) T(arg1, arg2, arg3); + } + // 4 args case. template<class T, class A1, class A2, class A3, class A4> T* InternalNew(A1 arg1, A2 arg2, A3 arg3, A4 arg4) diff --git a/src/pal/src/locale/utf8.cpp b/src/pal/src/locale/utf8.cpp index 4688cf0119..38599e6b08 100644 --- a/src/pal/src/locale/utf8.cpp +++ b/src/pal/src/locale/utf8.cpp @@ -20,6 +20,9 @@ Revision History: --*/ #include "pal/utf8.h" +#include "pal/malloc.hpp" + +using namespace CorUnix; #define FASTLOOP @@ -253,6 +256,8 @@ class DecoderFallbackBuffer // These wrap the internal methods so that we can check for people doing stuff that's incorrect public: + virtual ~DecoderFallbackBuffer() = default; + virtual bool Fallback(BYTE bytesUnknown[], int index, int size) = 0; // Get next character @@ -552,7 +557,7 @@ public: virtual DecoderFallbackBuffer* CreateFallbackBuffer() { - return new DecoderExceptionFallbackBuffer(); + return InternalNew<DecoderExceptionFallbackBuffer>(); } // Maximum number of characters that this instance of this fallback could return @@ -564,7 +569,7 @@ public: DecoderFallbackBuffer* DecoderReplacementFallback::CreateFallbackBuffer() { - return new DecoderReplacementFallbackBuffer(this); + return InternalNew<DecoderReplacementFallbackBuffer>(this); } class EncoderFallbackException : public ArgumentException @@ -728,6 +733,8 @@ class EncoderFallbackBuffer // These wrap the internal methods so that we can check for people doing stuff that is incorrect public: + virtual ~EncoderFallbackBuffer() = default; + virtual bool Fallback(WCHAR charUnknown, int index) = 0; virtual bool Fallback(WCHAR charUnknownHigh, WCHAR charUnknownLow, int index) = 0; @@ -1044,7 +1051,7 @@ public: virtual EncoderFallbackBuffer* CreateFallbackBuffer() { - return new EncoderExceptionFallbackBuffer(); + return InternalNew<EncoderExceptionFallbackBuffer>(); } // Maximum number of characters that this instance of this fallback could return @@ -1056,7 +1063,7 @@ public: EncoderFallbackBuffer* EncoderReplacementFallback::CreateFallbackBuffer() { - return new EncoderReplacementFallbackBuffer(this); + return InternalNew<EncoderReplacementFallbackBuffer>(this); } class UTF8Encoding @@ -1620,6 +1627,8 @@ public: Contract::Assert(fallback == nullptr || fallback->GetRemaining() == 0, "[UTF8Encoding.GetCharCount]Expected empty fallback buffer at end"); + InternalDelete(fallback); + return charCount; } @@ -2123,6 +2132,8 @@ public: Contract::Assert(fallback == nullptr || fallback->GetRemaining() == 0, "[UTF8Encoding.GetChars]Expected empty fallback buffer at end"); + InternalDelete(fallback); + return PtrDiff(pTarget, chars); } @@ -2511,6 +2522,8 @@ public: ch = 0; } + InternalDelete(fallbackBuffer); + return (int)(pTarget - bytes); } @@ -2838,6 +2851,8 @@ public: Contract::Assert(fallbackBuffer == nullptr || fallbackBuffer->GetRemaining() == 0, "[UTF8Encoding.GetByteCount]Expected Empty fallback buffer"); + InternalDelete(fallbackBuffer); + return byteCount; } diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index a1be42fa35..da55bff9c3 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -1544,7 +1544,7 @@ public: LONG ref = InterlockedDecrement(&m_ref); if (ref == 0) { - delete this; + InternalDelete(this); } return ref; } @@ -1836,7 +1836,7 @@ PAL_RegisterForRuntimeStartup( _ASSERTE(pfnCallback != NULL); _ASSERTE(ppUnregisterToken != NULL); - PAL_RuntimeStartupHelper *helper = new PAL_RuntimeStartupHelper(dwProcessId, pfnCallback, parameter); + PAL_RuntimeStartupHelper *helper = InternalNew<PAL_RuntimeStartupHelper>(dwProcessId, pfnCallback, parameter); // Create the debuggee startup semaphore so the runtime (debuggee) knows to wait for // a debugger connection. |