diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6e5788d4a..936d1dd90 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,7 +6,7 @@ jobs: - job: Linux pool: - vmImage: 'ubuntu-16.04' + vmImage: 'ubuntu-18.04' strategy: matrix: node_12_x: @@ -83,7 +83,7 @@ jobs: - Windows condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) pool: - vmImage: 'ubuntu-16.04' + vmImage: 'ubuntu-18.04' steps: - task: NodeTool@0 inputs: diff --git a/src/win/conpty.cc b/src/win/conpty.cc index 4500f6ef0..c5752572b 100644 --- a/src/win/conpty.cc +++ b/src/win/conpty.cc @@ -289,6 +289,13 @@ static NAN_METHOD(PtyConnect) { const v8::Local envValues = info[3].As(); const v8::Local exitCallback = v8::Local::Cast(info[4]); + // Fetch pty handle from ID and start process + pty_baton* handle = get_pty_baton(id); + if (!handle) { + Nan::ThrowError("Invalid pty handle"); + return; + } + // Prepare command line std::unique_ptr mutableCommandline = std::make_unique(cmdline.length() + 1); HRESULT hr = StringCchCopyW(mutableCommandline.get(), cmdline.length() + 1, cmdline.c_str()); @@ -311,9 +318,6 @@ static NAN_METHOD(PtyConnect) { auto envV = vectorFromString(env); LPWSTR envArg = envV.empty() ? nullptr : envV.data(); - // Fetch pty handle from ID and start process - pty_baton* handle = get_pty_baton(id); - BOOL success = ConnectNamedPipe(handle->hIn, nullptr); success = ConnectNamedPipe(handle->hOut, nullptr); @@ -396,15 +400,17 @@ static NAN_METHOD(PtyResize) { const pty_baton* handle = get_pty_baton(id); - HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0); - bool fLoadedDll = hLibrary != nullptr; - if (fLoadedDll) - { - PFNRESIZEPSEUDOCONSOLE const pfnResizePseudoConsole = (PFNRESIZEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ResizePseudoConsole"); - if (pfnResizePseudoConsole) + if (handle != nullptr) { + HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0); + bool fLoadedDll = hLibrary != nullptr; + if (fLoadedDll) { - COORD size = {cols, rows}; - pfnResizePseudoConsole(handle->hpc, size); + PFNRESIZEPSEUDOCONSOLE const pfnResizePseudoConsole = (PFNRESIZEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ResizePseudoConsole"); + if (pfnResizePseudoConsole) + { + COORD size = {cols, rows}; + pfnResizePseudoConsole(handle->hpc, size); + } } } @@ -424,18 +430,20 @@ static NAN_METHOD(PtyKill) { const pty_baton* handle = get_pty_baton(id); - HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0); - bool fLoadedDll = hLibrary != nullptr; - if (fLoadedDll) - { - PFNCLOSEPSEUDOCONSOLE const pfnClosePseudoConsole = (PFNCLOSEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ClosePseudoConsole"); - if (pfnClosePseudoConsole) + if (handle != nullptr) { + HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0); + bool fLoadedDll = hLibrary != nullptr; + if (fLoadedDll) { - pfnClosePseudoConsole(handle->hpc); + PFNCLOSEPSEUDOCONSOLE const pfnClosePseudoConsole = (PFNCLOSEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ClosePseudoConsole"); + if (pfnClosePseudoConsole) + { + pfnClosePseudoConsole(handle->hpc); + } } - } - CloseHandle(handle->hShell); + CloseHandle(handle->hShell); + } return info.GetReturnValue().SetUndefined(); } diff --git a/src/win/path_util.cc b/src/win/path_util.cc index 4e69f3091..841b47cae 100644 --- a/src/win/path_util.cc +++ b/src/win/path_util.cc @@ -52,7 +52,7 @@ std::wstring get_shell_path(std::wstring filename) { const wchar_t *filename_ = filename.c_str(); - for (int i = 0; i < paths.size(); ++i) { + for (size_t i = 0; i < paths.size(); ++i) { std::wstring path = paths[i]; wchar_t searchPath[MAX_PATH]; ::PathCombineW(searchPath, const_cast(path.c_str()), filename_);