Fix race condition in CreatePipeOverlapped

fixes #10510
This commit is contained in:
Gunnar Beutner 2015-11-01 12:59:57 +01:00
parent b2829ca522
commit ed90d9a847
1 changed files with 6 additions and 2 deletions

View File

@ -324,11 +324,15 @@ static BOOL CreatePipeOverlapped(HANDLE *outReadPipe, HANDLE *outWritePipe,
SECURITY_ATTRIBUTES *securityAttributes, DWORD size, DWORD readMode, DWORD writeMode)
{
static int pipeIndex = 0;
static boost::mutex mutex;
if (size == 0)
size = 8192;
pipeIndex++;
{
boost::mutex::scoped_lock lock(mutex);
pipeIndex++;
}
char pipeName[128];
sprintf(pipeName, "\\\\.\\Pipe\\OverlappedPipe.%d.%d", (int)GetCurrentProcessId(), pipeIndex);
@ -336,7 +340,7 @@ static BOOL CreatePipeOverlapped(HANDLE *outReadPipe, HANDLE *outWritePipe,
*outReadPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_INBOUND | readMode,
PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size, 60 * 1000, securityAttributes);
if (!*outReadPipe)
if (*outReadPipe == INVALID_HANDLE_VALUE)
return FALSE;
*outWritePipe = CreateFile(pipeName, GENERIC_WRITE, 0, securityAttributes, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | writeMode, NULL);