diff options
author | crntn <c.pescheloche@criteo.com> | 2018-02-27 19:42:56 +0100 |
---|---|---|
committer | Mike McLaughlin <mikem@microsoft.com> | 2018-02-27 10:42:56 -0800 |
commit | 32008c909e22a4ae290c616f8739da369161368a (patch) | |
tree | 7418d8933187b334d47928c79b671b34fec41efb /src/pal | |
parent | a3ecc73c54bf3d71668d286497844de0e33a0b69 (diff) | |
download | coreclr-32008c909e22a4ae290c616f8739da369161368a.tar.gz coreclr-32008c909e22a4ae290c616f8739da369161368a.tar.bz2 coreclr-32008c909e22a4ae290c616f8739da369161368a.zip |
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
Diffstat (limited to 'src/pal')
-rw-r--r-- | src/pal/inc/pal.h | 2 | ||||
-rw-r--r-- | 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); } |