Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1434e7f

Browse filesBrowse files
bzozMylesBorins
authored andcommitted
src: ensure that fd 0-2 are valid on windows
Check that stdin, stdout and stderr are valid file descriptors on Windows. If not, reopen them with 'nul' file. Refs: #875 Fixes: #11656 PR-URL: #11863 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 4a97bc7 commit 1434e7f
Copy full SHA for 1434e7f

File tree

Expand file treeCollapse file tree

3 files changed

+34
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+34
-1
lines changed
Open diff view settings
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,6 +4298,19 @@ inline void PlatformInit() {
42984298
} while (min + 1 < max);
42994299
}
43004300
#endif // __POSIX__
4301+
#ifdef _WIN32
4302+
for (int fd = 0; fd <= 2; ++fd) {
4303+
auto handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
4304+
if (handle == INVALID_HANDLE_VALUE ||
4305+
GetFileType(handle) == FILE_TYPE_UNKNOWN) {
4306+
// Ignore _close result. If it fails or not depends on used Windows
4307+
// version. We will just check _open result.
4308+
_close(fd);
4309+
if (fd != _open("nul", _O_RDWR))
4310+
ABORT();
4311+
}
4312+
}
4313+
#endif // _WIN32
43014314
}
43024315

43034316

Collapse file
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
import sys
3+
import subprocess
4+
os.close(0)
5+
os.close(1)
6+
os.close(2)
7+
exit_code = subprocess.call(sys.argv[1:], shell=False)
8+
sys.exit(exit_code)
Collapse file

‎test/parallel/test-stdio-closed.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stdio-closed.js
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@ const common = require('../common');
33
const assert = require('assert');
44
const spawn = require('child_process').spawn;
55
const fs = require('fs');
6+
const path = require('path');
67

78
if (common.isWindows) {
8-
common.skip('platform not supported.');
9+
if (process.argv[2] === 'child') {
10+
process.stdin;
11+
process.stdout;
12+
process.stderr;
13+
return;
14+
}
15+
const python = process.env.PYTHON || 'python';
16+
const script = path.join(common.fixturesDir, 'spawn_closed_stdio.py');
17+
const proc = spawn(python, [script, process.execPath, __filename, 'child']);
18+
proc.on('exit', common.mustCall(function(exitCode) {
19+
assert.strictEqual(exitCode, 0);
20+
}));
921
return;
1022
}
1123

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.