From 32008c909e22a4ae290c616f8739da369161368a Mon Sep 17 00:00:00 2001 From: crntn Date: Tue, 27 Feb 2018 19:42:56 +0100 Subject: [PATCH] Debugger FIFO pipes are created in TMPDIR if defined #16234 (#16452) Debugger FIFO pipes are created in TMPDIR if defined #16234 Init name to null termination to ensure failure if GetTempPathA fails --- src/pal/inc/pal.h | 2 +- src/pal/src/thread/process.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index affe5556dd..18fbdab8bc 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -480,7 +480,7 @@ BOOL PALAPI PAL_NotifyRuntimeStarted(VOID); -static const int MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH = 64; +static const int MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH = MAX_PATH; PALIMPORT VOID diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index 7c9014ed49..a1be42fa35 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -1462,7 +1462,7 @@ static uint64_t HashSemaphoreName(uint64_t a, uint64_t b) #define HashSemaphoreName(a,b) a,b #endif -static const char* PipeNameFormat = TEMP_DIRECTORY_PATH "clr-debug-pipe-%d-%llu-%s"; +static const char* PipeNameFormat = "clr-debug-pipe-%d-%llu-%s"; class PAL_RuntimeStartupHelper { @@ -2097,7 +2097,10 @@ PAL_GetTransportPipeName( IN DWORD id, IN const char *suffix) { + *name = '\0'; + DWORD dwRetVal = 0; UINT64 disambiguationKey = 0; + char formatBuffer[MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH]; BOOL ret = GetProcessIdDisambiguationKey(id, &disambiguationKey); // If GetProcessIdDisambiguationKey failed for some reason, it should set the value @@ -2105,7 +2108,26 @@ PAL_GetTransportPipeName( // also try to use 0 as the value. _ASSERTE(ret == TRUE || disambiguationKey == 0); - int chars = snprintf(name, MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, PipeNameFormat, id, disambiguationKey, suffix); + // Get a temp file location + dwRetVal = ::GetTempPathA(MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, formatBuffer); + if (dwRetVal == 0) + { + ERROR("GetTempPath failed (0x%08x)", ::GetLastError()); + return; + } + if (dwRetVal > MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH) + { + ERROR("GetTempPath returned a path that was larger than MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH"); + return; + } + + if (strncat_s(formatBuffer, _countof(formatBuffer), PipeNameFormat, strlen(PipeNameFormat)) == STRUNCATE) + { + ERROR("TransportPipeName was larger than MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH"); + return; + } + + int chars = snprintf(name, MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH, formatBuffer, id, disambiguationKey, suffix); _ASSERTE(chars > 0 && chars < MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH); } -- 2.34.1