node-pty 0.11.0-beta2 → 0.11.0-beta20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/win/conpty.cc CHANGED
@@ -289,6 +289,13 @@ static NAN_METHOD(PtyConnect) {
289
289
  const v8::Local<v8::Array> envValues = info[3].As<v8::Array>();
290
290
  const v8::Local<v8::Function> exitCallback = v8::Local<v8::Function>::Cast(info[4]);
291
291
 
292
+ // Fetch pty handle from ID and start process
293
+ pty_baton* handle = get_pty_baton(id);
294
+ if (!handle) {
295
+ Nan::ThrowError("Invalid pty handle");
296
+ return;
297
+ }
298
+
292
299
  // Prepare command line
293
300
  std::unique_ptr<wchar_t[]> mutableCommandline = std::make_unique<wchar_t[]>(cmdline.length() + 1);
294
301
  HRESULT hr = StringCchCopyW(mutableCommandline.get(), cmdline.length() + 1, cmdline.c_str());
@@ -311,11 +318,8 @@ static NAN_METHOD(PtyConnect) {
311
318
  auto envV = vectorFromString(env);
312
319
  LPWSTR envArg = envV.empty() ? nullptr : envV.data();
313
320
 
314
- // Fetch pty handle from ID and start process
315
- pty_baton* handle = get_pty_baton(id);
316
-
317
- BOOL success = ConnectNamedPipe(handle->hIn, nullptr);
318
- success = ConnectNamedPipe(handle->hOut, nullptr);
321
+ ConnectNamedPipe(handle->hIn, nullptr);
322
+ ConnectNamedPipe(handle->hOut, nullptr);
319
323
 
320
324
  // Attach the pseudoconsole to the client application we're creating
321
325
  STARTUPINFOEXW siEx{0};
@@ -396,15 +400,17 @@ static NAN_METHOD(PtyResize) {
396
400
 
397
401
  const pty_baton* handle = get_pty_baton(id);
398
402
 
399
- HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
400
- bool fLoadedDll = hLibrary != nullptr;
401
- if (fLoadedDll)
402
- {
403
- PFNRESIZEPSEUDOCONSOLE const pfnResizePseudoConsole = (PFNRESIZEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ResizePseudoConsole");
404
- if (pfnResizePseudoConsole)
403
+ if (handle != nullptr) {
404
+ HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
405
+ bool fLoadedDll = hLibrary != nullptr;
406
+ if (fLoadedDll)
405
407
  {
406
- COORD size = {cols, rows};
407
- pfnResizePseudoConsole(handle->hpc, size);
408
+ PFNRESIZEPSEUDOCONSOLE const pfnResizePseudoConsole = (PFNRESIZEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ResizePseudoConsole");
409
+ if (pfnResizePseudoConsole)
410
+ {
411
+ COORD size = {cols, rows};
412
+ pfnResizePseudoConsole(handle->hpc, size);
413
+ }
408
414
  }
409
415
  }
410
416
 
@@ -424,18 +430,24 @@ static NAN_METHOD(PtyKill) {
424
430
 
425
431
  const pty_baton* handle = get_pty_baton(id);
426
432
 
427
- HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
428
- bool fLoadedDll = hLibrary != nullptr;
429
- if (fLoadedDll)
430
- {
431
- PFNCLOSEPSEUDOCONSOLE const pfnClosePseudoConsole = (PFNCLOSEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ClosePseudoConsole");
432
- if (pfnClosePseudoConsole)
433
+ if (handle != nullptr) {
434
+ HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
435
+ bool fLoadedDll = hLibrary != nullptr;
436
+ if (fLoadedDll)
433
437
  {
434
- pfnClosePseudoConsole(handle->hpc);
438
+ PFNCLOSEPSEUDOCONSOLE const pfnClosePseudoConsole = (PFNCLOSEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ClosePseudoConsole");
439
+ if (pfnClosePseudoConsole)
440
+ {
441
+ pfnClosePseudoConsole(handle->hpc);
442
+ }
435
443
  }
436
- }
437
444
 
438
- CloseHandle(handle->hShell);
445
+ DisconnectNamedPipe(handle->hIn);
446
+ DisconnectNamedPipe(handle->hOut);
447
+ CloseHandle(handle->hIn);
448
+ CloseHandle(handle->hOut);
449
+ CloseHandle(handle->hShell);
450
+ }
439
451
 
440
452
  return info.GetReturnValue().SetUndefined();
441
453
  }
@@ -52,7 +52,7 @@ std::wstring get_shell_path(std::wstring filename) {
52
52
 
53
53
  const wchar_t *filename_ = filename.c_str();
54
54
 
55
- for (int i = 0; i < paths.size(); ++i) {
55
+ for (size_t i = 0; i < paths.size(); ++i) {
56
56
  std::wstring path = paths[i];
57
57
  wchar_t searchPath[MAX_PATH];
58
58
  ::PathCombineW(searchPath, const_cast<wchar_t*>(path.c_str()), filename_);
@@ -40,7 +40,8 @@ export class ConoutConnection implements IDisposable {
40
40
  private _conoutPipeName: string
41
41
  ) {
42
42
  const workerData: IWorkerData = { conoutPipeName: _conoutPipeName };
43
- this._worker = new Worker(join(__dirname, 'worker/conoutSocketWorker.js'), { workerData });
43
+ const scriptPath = __dirname.replace('node_modules.asar', 'node_modules.asar.unpacked');
44
+ this._worker = new Worker(join(scriptPath, 'worker/conoutSocketWorker.js'), { workerData });
44
45
  this._worker.on('message', (message: ConoutWorkerMessage) => {
45
46
  switch (message) {
46
47
  case ConoutWorkerMessage.READY:
@@ -42,7 +42,7 @@ declare module 'node-pty' {
42
42
  /**
43
43
  * Environment to be set for the child program.
44
44
  */
45
- env?: { [key: string]: string };
45
+ env?: { [key: string]: string | undefined };
46
46
 
47
47
  /**
48
48
  * String encoding of the underlying pty.
@@ -78,11 +78,17 @@ declare module 'node-pty' {
78
78
 
79
79
  export interface IPtyForkOptions extends IBasePtyForkOptions {
80
80
  /**
81
- * Security warning: use this option with great caution, as opened file descriptors
82
- * with higher privileges might leak to the child program.
81
+ * Security warning: use this option with great caution unless `closeFDs` is also set,
82
+ * as opened file descriptors with higher privileges might leak to the child program.
83
83
  */
84
84
  uid?: number;
85
85
  gid?: number;
86
+
87
+ /**
88
+ * Close all open file after spawning the child process (UNIX only).
89
+ * Carries a performance penalty on Linux.
90
+ */
91
+ closeFDs?: boolean;
86
92
  }
87
93
 
88
94
  export interface IWindowsPtyForkOptions extends IBasePtyForkOptions {
@@ -165,7 +171,7 @@ declare module 'node-pty' {
165
171
 
166
172
  /**
167
173
  * Resizes the dimensions of the pty.
168
- * @param columns THe number of columns to use.
174
+ * @param columns The number of columns to use.
169
175
  * @param rows The number of rows to use.
170
176
  */
171
177
  resize(columns: number, rows: number): void;