]> granicus.if.org Git - icinga2/commitdiff
Fix race condition in CreatePipeOverlapped
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 10 Aug 2016 10:12:56 +0000 (12:12 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 10 Aug 2016 10:12:56 +0000 (12:12 +0200)
fixes #10075

lib/base/process.cpp

index 831bf36ae1919fb826226e14b45933d63f165b91..76628cce28d82f18876ad8cc700beaa00e5dc407 100644 (file)
@@ -329,13 +329,16 @@ static BOOL CreatePipeOverlapped(HANDLE *outReadPipe, HANDLE *outWritePipe,
        if (size == 0)
                size = 8192;
 
+       int currentIndex;
+
        {
                boost::mutex::scoped_lock lock(mutex);
+               currentIndex = pipeIndex;
                pipeIndex++;
        }
 
        char pipeName[128];
-       sprintf(pipeName, "\\\\.\\Pipe\\OverlappedPipe.%d.%d", (int)GetCurrentProcessId(), pipeIndex);
+       sprintf(pipeName, "\\\\.\\Pipe\\OverlappedPipe.%d.%d", (int)GetCurrentProcessId(), currentIndex);
 
        *outReadPipe = CreateNamedPipe(pipeName, PIPE_ACCESS_INBOUND | readMode,
            PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size, 60 * 1000, securityAttributes);