Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address codeql bugs #508

Merged
merged 4 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
jobs:
- job: Linux
pool:
vmImage: 'ubuntu-16.04'
vmImage: 'ubuntu-18.04'
strategy:
matrix:
node_12_x:
Expand Down Expand Up @@ -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:
Expand Down
48 changes: 28 additions & 20 deletions src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ static NAN_METHOD(PtyConnect) {
const v8::Local<v8::Array> envValues = info[3].As<v8::Array>();
const v8::Local<v8::Function> exitCallback = v8::Local<v8::Function>::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<wchar_t[]> mutableCommandline = std::make_unique<wchar_t[]>(cmdline.length() + 1);
HRESULT hr = StringCchCopyW(mutableCommandline.get(), cmdline.length() + 1, cmdline.c_str());
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/win/path_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t*>(path.c_str()), filename_);
Expand Down